the answer should be by matlab code Write an Mscript file en
the answer should be by matlab code
Write an M-script file entitled Probleml 4.m to do the following. Find the minimums of 025x 0625x 333x3 x Which is the global minimum?Solution
%Write two programs which find the roots of a quadratic. For the first, use
%the standard quadratic
%formula. For the second, modify the formula so that the term
%
%is replaced with a more stable formula. Test both formulas on f (x) = x2 ? 50000x + 1. How
%close are your roots to the true solution?
% This m-file will solve the quadratic equation :ax^2 + bx + c = 0
function Quad= Quadratic(A,B,C)
% A=1;
% B=2;
% C=3;
%If-Else statement for if A=0
if A==0,
X= -C/B;
else
X(1) = (-B+sqrt(B^2-4*A*C))/(2*A);
X(2) = (-B-sqrt(B^2-4*A*C))/(2*A);
disp(X(1))
disp(X(2))
fprintf(\'X(1) = %f \ \',X(1));
fprintf(\'X(2) = %f \ \',X(2));
end
> \"Don \" <don.jackson@coker.edu> wrote in message <icpmt1$seh$1@fred.mathworks.com>...
> > Ok so this programming assignment calls for:
> >
> > Write two programs which find the roots of a quadratic. For the first, use the standard quadratic
> > formula. For the second, modify the formula so that the term
> > is replaced with a more stable formula. Test both formulas on f (x) = x2 ???? 50000x + 1. How close are your roots to the true solution?
> >
> >
> > Questions: How do I make it into a more stable formula and how do i test the roots?
> >
> > Here is my code:
> >
> > %Write two programs which find the roots of a quadratic. For the first, use
> > %the standard quadratic
> > %formula. For the second, modify the formula so that the term
> > %
> > %is replaced with a more stable formula. Test both formulas on f (x) = x2 ? 50000x + 1. How
> > %close are your roots to the true solution?
> >
> >
> > % This m-file will solve the quadratic equation :ax^2 + bx + c = 0
> >
> > function Quad= Quadratic(A,B,C)
> >
> > % A=1;
> > % B=2;
> > % C=3;
> >
> >
> > %If-Else statement for if A=0
> >
> > if A==0,
> > X= -C/B;
> > else
> > X(1) = (-B+sqrt(B^2-4*A*C))/(2*A);
> > X(2) = (-B-sqrt(B^2-4*A*C))/(2*A);
> >
> > disp(X(1))
> > disp(X(2))
> > fprintf(\'X(1) = %f \ \',X(1));
> > fprintf(\'X(2) = %f \ \',X(2));
> >
> >
> > end
>
>
>
> can you please tell
>
> if A===
>
> how is X=-C/B and not -B/A ?
>
> regards
The original equation is
Ax^2+Bx+C=0.
Now if A=0, the equation left is
Bx+C=0, thus x=-C/B.
Best wishes
Torsten.

