Matlab needed to do this 1 4 points write the script or func

Matlab needed to do this.
1. 4 points] write the script or function m-file to compute s- ei, where E 1 indicates the summation from n-1 to M and run the case M-10. (a) Using forlend, but not array operators or sum. This is the standard. (b) Using array operators and sum, but not forhend. Hint: Create an array of ratios C,i Nil using the array operator] Submit the codes and the numerical results. 2. [3 points) write a function m-file that calculates the roots of ax bx c 0. Its synopsis is Quad Roots (a,b,c), where a, b and c are allowed to be vectors. First, use the example below to get the results (and show them), then give your own input of coefficient vectors a, b and c and perform the calculation and show the results. Finally, check your results with the roots command, which is a built-in MATLAB command to do the job. For example a (1,2,3,5,5]; b [2,2,4,5,6]; c (3,4,4,6,70; will produce the coefficients of five quadratic polynomials: x2 2x 3 2x2 2x 4-0 3x2 4x 4 0 5x2 5x 6 m When you issue the command Quad Roots (a,b,c) you will get five set of roots of these five equations. The size of coefficient vectors a, b and c must be the same (in this case 1 x 5) but could be arbitrary (does not have to be 5 as above) The roots of a quadratic polynomial, as defined here, are given by the formula btva where the discriminant is defined by d b2 4ac. Depending on the sign of the discriminant you get either the real of complex roots. Therefore you need to include a segment of codes that distinguishes the case when d b2 4ac is positive, negative and zero. You can use if, elseif, else, end construct for this. Note that, when d is negative, MATLAB automatically produces complex roots, but do not rely on this capability and use the form x tead, where i is the imaginary number eBasic concepts Islam doc M N Makhdoom Resu... docx e syllabus F16 seco1 doc

Solution

% m-file to solve the quadratic equation :ax^2 + bx + c = 0

function Quad= QuadRoots(A,B,C)

A=[1 2 3 5 5];
B=[2 2 4 5 6];
C=[3 4 4 6 7];

for i=1:5
%If-Else statement for if A=0
fprintf(\'Root calculation at vector value = %f\ \',i);
if A(i)==0
X3= -C(i)/B(i);
disp(X3)
fprintf(\'X(3) = %f \ \',X3);
else
D(i) = B(i)^2-4*A(i)*C(i);
X1 = (-B(i)+sqrt(D(i)))/(2*A(i));
X2 = (-B(i)-sqrt(D(i)))/(2*A(i));
disp(X1)
disp(X2)
fprintf(\'X(1) = %f \ \',X1);
fprintf(\'X(2) = %f \ \',X2);
end
  
end

Matlab needed to do this. 1. 4 points] write the script or function m-file to compute s- ei, where E 1 indicates the summation from n-1 to M and run the case M-

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site