Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

USING MATLAB Series solutions are often a convenient way to approximate an answe

ID: 3108886 • Letter: U

Question

USING MATLAB

Series solutions are often a convenient way to approximate an answer for complex equations, especially with partial differential equations. A simple example of this approximation is the series solution for sin. Sin(x) = x - x^3/3! + x^5! - x^7/7! ... = sigma (-1)^n+1 x^(2n-1)/(2n - 1)! Where n is a positive integer starting from going from 1 to infinity. in this in class assignment we will explore the use of this series solution for sin and evaluate its accuracy a. Create a m-file function called sinner that takes 2 inputs, x and i, where x is the angle in radians that you are attempting to find the sin of and i is the maximum value of n that you want to carry the series solution out to. To achieve this goal use a FOR LOOP to solve this expression. Each step of the interaction you will sum the previous result with the new term. a. Use the equation given in the summation symbol to find each step of the value b. Use the function factorial() to find the factorial of the term (2n-1) c. Note you do not need to use array math as we will use this as just scalars for purposes of this function b. Now that you have a function that works on a "for loop", you can now ask matlab to repeat using that function with increasing values of n until a specific level of accuracy is achieved. To do this, write a while loop which checks that a precision is less than or equal to 0.0001. Run this code for the value of x = 5;

Explanation / Answer

a)

function f=sinapp(x,n)
s(1)=0;
for i=1:n+1
s(i+1)=s(i)+(((-1)^(i-1)/(factorial(2*(i-1)+1)))*x^(2*(i-1)+1));
end

end

Note: u have to give file name sinaap and save it. then give x and n value it will work;

b)

clc;
clear all;
x=5
err=0.1;
tol=0.0001 % tolerence
n=1;
while(err>tol)
s(1)=0;
for i=1:n+1
s(i+1)=s(i)+(((-1)^(i-1)/(factorial(2*(i-1)+1)))*x^(2*(i-1)+1));
end

err=abs(sin(5)-s(end)) %error
n=n+1
end
s(end)

%RESULT

err =

8.8905e-006


n =

10


ans =

-0.9589