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

Using MATLAB: The sin function sin(x) can be approximated by the following formu

ID: 3663234 • Letter: U

Question

Using MATLAB:

The sin function sin(x) can be approximated by the following formula for all x. [25] Write a function using loops that computes an approximation to sin function sin(x) using the above formula. Your function must take x and n as function input arguments, n is the number of terms you want to keep in your approximation. The approximation will get more accurate if you keep more terms. Re-write your function using vectorization techniques. How many terms you need to approximate sin(20) = 0.912945 to six decimal digits? Write a script to compute the minimum number of terms you need and print out your result in seven decimal digits on the screen as follows: It takes n=1000 terms to approximate sin(20) = 0.912945 to six digits, the approximation is 0.9129451.

Explanation / Answer

a)

function [y] = sin(x,n)
y = 0
for i = 0:n
y = y+ (-1)^i*x^(2*i+1)/factorial(2*i+1);
end
end % end of sin

Calling function


sin(pi/3,10)

OUTPUT

---------------------------------------------------------------------------------------------------------------------------

USING Vectorization

function [y] = sin(x,n)
y = 0
for i = 0:n % vector loop
y = y+ (-1)^i*x^(2*i+1)/factorial(2*i+1);
end
end % end of sin

Calling function


sin(pi/3,10)

OUTPUT

-------------------------------------------------------------------------------------------------------------------------------------------------

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote