Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

N=[1,2,3,4,5]; s1=[0,0,0,0,0]; c1=s1;e1=c1; x=pi/3; for i=1:5 for j=0:N(i) s1(i)=s1(i)+(-1)^j*x^(2*j+1)/factorial(2*j+1); end end e1=abs(sin(x)-s1); fprintf('Part a) sin(pi/3) ') fprintf('S(%i) = %.10f, Error = %.15e. ',[N;s1;e1]) x=pi/4; for

image text in transcribed

image text in transcribed

N=[1,2,3,4,5]; s1=[0,0,0,0,0]; c1=s1;e1=c1; x=pi/3; for i=1:5 for j=0:N(i) s1(i)=s1(i)+(-1)^j*x^(2*j+1)/factorial(2*j+1); end end e1=abs(sin(x)-s1); fprintf('Part a) sin(pi/3) ') fprintf('S(%i) = %.10f, Error = %.15e. ',[N;s1;e1]) x=pi/4; for i=1:5 for j=0:N(i) c1(i)=c1(i)+((-1)^j)*(x^(2*j))/factorial(2*j); end end e1=abs(cos(x)-c1); fprintf('Part b) cos(pi/4) ') fprintf('S(%i) = %.10f, Error = %.15e. ',[N;c1;e1]) x=-2; e1=[0,0,0,0,0]; for i=1:5 for j=0:N(i) e1(i)=e1(i)+x^j/(factorial(j)); end end e=abs(exp(x)-e1); fprintf('Part c) exp(-2) ') fprintf('S(%i) = %.10f, Error = %.15e. ',[N;e1;e])

I have codes for PART 2. I need PART 3.

HW6P3 (25 points) Using the functions mentioned in HW6P2. Prompt the user for the name of a function (sin, r exp). If the user enters something else other than the exact function name, the program must display an error message and re-prompt the user to enter one of the three functions until the user enters a valid entry. The program should then prompt the user to enter a value of x for the corresponding function, i.e. function-sin, x- pi/3 means that sin(pi/3) will be evaluated. Lastly, the program should prompt the user to enter the number of terms to be included in the partial sum, N, as an integer >0. If the user enters an invalid number, the program must display an error message and re-prompt the user to enter in the number of terms. HINT: Use a while loop for valid entry. Use the stremp ) function for comparison between strings and the rem() function to determine if a number is an integer Your program must use a branching structure if-else or switch-case to execute only the function entered by the user and determine its value at x entered. Use a for loop to compute the partial sum Sn for the specified N entered by the user. The program then must print the result to the command window as seen below. function (x) out to N terms x.xxxxxx Example output where function sin, x - pi/6, and N-5: sin (0.523599) out to 5 terms = -0.500000 You may test your script for the following cases with N -5, 10, and 20: i. sin(0), sin(-/6), sin(/4), sin(t/3), sin(t/2), sin(3Tt/2) 11. cos(0), cos(-r/6), cos(n/4), cos(n/3), cos(n/2), cos(3r/2) ii. exp(0),exp(-2), exp(3),exp(-5), exp (3.5) iv. SIN(0), CoS(-n/6), EXP (3) v. sin (cos, cos ( exp(2.5) with N -0 and - 10

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Introduction To Databases And Data Warehouses

Authors: Nenad Jukic, Susan Vrbsky, Svetlozar Nestorov

1st Edition

1943153191, 978-1943153190

More Books

Students also viewed these Databases questions

Question

Differentiate between team building and managing teams.

Answered: 1 week ago