Question

Please show me the MATLAB CODE for this problem Thank you Write programs that determine solutions...

Please show me the MATLAB CODE for this problem Thank you

Write programs that determine solutions for polynomials (quadratics, et al)

  1. a) Create a program that presumes the user-entered values (a,b,c) represent a valid quadratic equation and your initial program simply solves the equation and reports the real or imaginary roots.

  2. b) Create a flowchart that describes all possible combinations of user entered data, e.g. perhaps a user enters (1, 0, -4) as (a, b, c) which is of course results in:

    22
    ax+bx+c=0 → x−4=0or=±x2

  3. c) Create an efficient and user-friendly program that accepts any combination of constants (a,b,c) and returns the correct roots for the appropriate polynomial.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

clear all ;
close all
clc

% the equation will be in the form
% a*x^2 + b*x + c =0
prompt = {'Enter a ','Enter b ','Enter c'};
dlg_title = 'Input';
num_lines = 1;
defaultans = {'1','6','4'};
answer = inputdlg(prompt,dlg_title,num_lines,defaultans);
a = str2double(answer{1});
b = str2double(answer{2});
c = str2double(answer{3});

D = b^2-4*a*c;
if D < 0
root1 = strcat(num2str(-b/2/a),'+',num2str(sqrt(abs(D))/2/a),'*I');
root2 = strcat(num2str(-b/2/a),'-',num2str(sqrt(abs(D))/2/a),'*I');
if b == 0
root1 = strcat(num2str(sqrt(abs(D))/2/a),'*I');
root2 = strcat('-',num2str(sqrt(abs(D))/2/a),'*I');
end
elseif D == 0
root1 = num2str(-b/2/a);
root2 = num2str(-b/2/a);
else
root1 = num2str(-b/2/a+sqrt(D)/2/a);
root2 = num2str(-b/2/a-sqrt(D)/2/a);
end

fprintf('%s = %s \n','root 1',root1)
fprintf('%s = %s \n','root 2',root2)

COMMENT DOWN FOR ANY QUERIES AND,

LEAVE A THUMBS UP IF THIS ANSWER HELPS YOU.

Add a comment
Know the answer?
Add Answer to:
Please show me the MATLAB CODE for this problem Thank you Write programs that determine solutions...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • write a C programming code for the following prompt. please use stucture concept and test if...

    write a C programming code for the following prompt. please use stucture concept and test if the code works perfectly. Project Description: In this project, you will write a program to calculate the roots of a quadratic equation. Structure concepts will be used in this project. Your program will prompt the user to enter the coefficients of a quadra coefficientsType. Then it will compute the roots of the quadratic equation and store the result in a structure variable of type...

  • please answer this question with python. Write a program to solve the quadratic equation ax^2 +...

    please answer this question with python. Write a program to solve the quadratic equation ax^2 + bx + c = 0 using the standard quadratic formula x = -b plusminus Squareroot b^2 - 4ac/2a or the alternative formula x = 2c/-b Squareroot b^2 - 4ac. Your program should accept values for the coefficients a, b, and c as input and produce the two roots of the equation as output. Your program should detect when the roots are imaginary, but need...

  • PLEASE USE MATLAB. THANK YOU! Consider the following polynomial equation: ax3 bx2 cx d 0 Write a program that allows th...

    PLEASE USE MATLAB. THANK YOU! Consider the following polynomial equation: ax3 bx2 cx d 0 Write a program that allows the user to enter the coefficients a,b,c and d and the search range needed for the Bisection method. The program should stop when the maximum error is less than 0.01. The program should display the root and also have a condition to stop when no roots are found in the range. Consider the following polynomial equation: ax3 bx2 cx d...

  • #PLEASE WRITE THE CODE IN JAVA! THANK YOU IN ADVANCE! Write a program that manages a...

    #PLEASE WRITE THE CODE IN JAVA! THANK YOU IN ADVANCE! Write a program that manages a list of up to 10 players and their high scores in the computer's memory. Use two arrays to manage the list. One array should store the players' names, and the other array should store the players' high scores. Use the index of the arrays to correlate the names with the scores. Your program should support the following features: a. Add a new player and...

  • C-Programming please. The task is to create second-degree polynomial calculator for the function, its integral and...

    C-Programming please. The task is to create second-degree polynomial calculator for the function, its integral and its derivative. A second-degree polynomial is described by the equation f(x) = ax +bx+c. Evaluation of the derivative gives the instantaneous slope or rate of change as (where f'(x) is the derivative of f(x)): f"(x)=2x+b The integral of the function f(x) (let us call it F(x)) indicates the area underneath the curve. Between points x; and the area A is A = F(x)-F(x), where,...

  • please do this problem in matlab and show me the code. Thanks. please do this problem...

    please do this problem in matlab and show me the code. Thanks. please do this problem in Matlab and show me the code. Thanks. Problem #1: Circuits and linear-systems In the last HW you developed the governing equations for the “Wheatstone”-bridge circuit used extensively in engineering applications (shown below). B R R2 A D G m RA с E The resulting equations were solved for the output voltage and currents using the function: function [V_out, I_vector] =Wheatstone_bridge (v_in, R_vector) In...

  • please do this problem in matlab and show me the code. Thanks. please do this problem...

    please do this problem in matlab and show me the code. Thanks. please do this problem in matlab and show me the code. Thanks. please do this problem in matlab and show me the code. Thanks. please do this problem in matlab and show me the code. Thanks. please do this problem in matlab and show me the code. Thanks.please do this problem in matlab and show me the code. Thanks. please do this problem in matlab and show me...

  • I want to know how to do this assignment!!! Help me please~ The first part of...

    I want to know how to do this assignment!!! Help me please~ The first part of your program should do the following: • Ask the user type of test they took. o (ACT or SAT) • If they said ACT then ask them their score o If their ACT score was between 0 and 7 say "Needs Work" o If their ACT score was between 10 and 20 say "Acceptable" o If they ACT score was above 20 say "Above...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT