answersLogoWhite

0


Best Answer

array=input('Specify the coefficients of the quadratic as a row array "[a,b,c]":');

a=array(1);

b=array(2);

c=array(3);

if (a==0) && (b==0)

fprintf('The equation is degenerate');

end

if (a==0) && (b~=0)

fprintf('There is a single root at %g.\n', -c/b);

end

if (a~=0) && (c==0)

fprintf('There are two real roots at 0 and %g.\n', -b/a);

end

if (a~=0) && (c~=0)

root1=((-b+sqrt(b*b-4*a*c))/(2*a));

root2=((-b-sqrt(b*b-4*a*c))/(2*a));

if isreal(root1)

fprintf('There are two real roots at %g and %g.\n.', root1, root2);

else

fprintf('The roots are complex:\n');

fprintf(' ');

disp(root1);

fprintf(' and ');

disp(root2);

end

end

User Avatar

Wiki User

11y ago
This answer is:
User Avatar
More answers
User Avatar

AnswerBot

6mo ago

You can solve a quadratic equation in MATLAB using the quadratic formula. Here is an example code snippet:

a = 1; b = 5; c = 6;

delta = b^2 - 4ac;

if delta > 0 x1 = (-b + sqrt(delta))/(2a); x2 = (-b - sqrt(delta))/(2a); disp(['The solutions are: x1 = ', num2str(x1), ', x2 = ', num2str(x2)]); elseif delta == 0 x = -b/(2*a); disp(['The solution is: x = ', num2str(x)]); else disp('No real solutions'); end

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program in matlab that solve a quadratic equation?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Write an algorithm to find the root of quadratic equation?

Write an algorithm to find the root of quadratic equation


Algorithm to find the roots of a quadratic equation?

The easiest way to write a generic algorithm is to simply use the quadratic formula. If it is a computer program, ask the user for the coefficients a, b, and c of the generic equation ax2 + bx + c = 0, then just replace them in the quadratic formula.


How did you write each quadratic equation in standard form?

readuse the answer


How do you write a poem on the roots of the quadratic equation?

2000X=Y2KoverZzz?


Write a program in C programming language that computes the roots of the quadratic equation ax2 plus bx plus c?

Write your program and if you are having a problem post it here with a description of the problem you are having. What you are asking is for someone to do your homework for you.


How would you go about solving a quadratic equation?

Write the quadratic equation in the form ax2 + bx + c = 0 then the roots (solutions) of the equation are: [-b ± √(b2 - 4*a*c)]/(2*a)


How do you write a pseudo code for find the quadratic equation?

computer scince


How do you write a quadratic equation in standard form?

ax2 + bx + c


When the roots are equal of a quadratic equation?

Write the quadratic equation in the form ax2 + bx + c = 0 The roots are equal if and only if b2 - 4ac = 0. The expression, b2-4ac is called the [quadratic] discriminant.


Write an algorithm and draw a flowchart that will calculate the roots of quadratic equation?

dejene


What are the difference between matlab and c language?

Matlab is a scripting and mathematical language processor for working with mathematical equations. C is a structured programming language for writing programs. Those programs can contain mathematical equations, but they won't be in quite the same format that you're used to from math class. Matlab will solve and equation for you. C will allow you to write a program that solves the equation. C++ is an object-oriented version of C. matlab and simulink let us design,simulate,implement & test a variety of time varying system


What are all the ways you can solve a quadratic equation?

First, write the equation in standard form, i.e., put zero on the right. Then, depending on the case, you may have the following options:Factor the polynomialComplete the squareUse the quadratic formula