Question: what is wrong with my matlab code clc; function approx = cosineApprox(x,t) approx = 1 for i=1:1:t-1 nextTerms = (-1)^i*(x^(2*i))/factorial(2*i); approx = approx + nextTerm;

what is wrong with my matlab code clc; function approx = cosineApprox(x,t)approx = 1 for i=1:1:t-1 nextTerms = (-1)^i*(x^(2*i))/factorial(2*i); approx = approx +nextTerm; end end x = 2*pi/3; actual = cos(x); disp("original value:"); disp(actual);what is wrong with my matlab code

clc;

function approx = cosineApprox(x,t)

approx = 1

for i=1:1:t-1

nextTerms = (-1)^i*(x^(2*i))/factorial(2*i);

approx = approx + nextTerm;

end

end

x = 2*pi/3;

actual = cos(x);

disp("original value:");

disp(actual);

t = input("number of terms:");

approx = cosineApprox(x,t);

disp("approximate value:");

disp(approx);

-0.4996 >> approx = approxcosineFunction(x, 10) approX - -0.5000

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!