Question

Write a matlab program to apply Horner's algorithm to evaluate the sum of the first four...

Write a matlab program to apply Horner's algorithm to evaluate the sum of the first four nonzero terms of the Taylor series for sin(x) with c=0. Your program should not use any arrays, the exponentiation operator or the factorial function. Print out your program and include the output upon execution for the special case where x = 1. How many nonzero terms of the above Taylor series are needed to guarantee that the sum approximates sin(x) to within .0001 for any x with -π /2 < x < π /2. Show your computations.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Below is the code for your question:

clc%clears console
clear all%clears the history
close all;
syms f(x)
f(x)=sin(x);
F=f;
count=0;
j=0;
while(count~=4)
F=diff(F);
if(F(0)~=0)
count=count+1;
end
j=j+1;
end
sum=0;
for i=j:-1:0
sum=sum*x/(i+1)+(F);
F=int(F);
end
disp(sum)
fprintf('Taylor series with fith first 4 non zero sums of sinx at x=1 is: %.10f',eval(sum(1)));

execution:

MATLAB R2014a HOME PLOTS EDITOR E caren Documentat on Find Files Compare Comment Print ▼ Run Section 변 96 돼 Go To▼ Find New Open Save Breakpoints Run Run and Advance Run nd Advance Timc ÷ ÷ H 、 F: Polycrystal-sample-generation» ト Current Folder Editor-C:AUsers PRADEEP KALRADocumentsMATLABjacobi.m Name abi.m arnoldi.m* newtonrapsonsbypradeep.m yyttmhyperboloidbypradeep.m hyperboloidbypradeep2.m xparabolloidbypradeep.m+ Extra_data_not in-use i polycrystals wnile count-,-4 ) 10-F-diff (F) 11-1 if(F(0) 0) 12- 13 end 14- 15- end 1.geo count-count+1; 3.geo 4.geo Details Workspace Name ▲ 18- | sur-sum1x/(i+1)+/F); 19-F int (F) 20end 21-d1sp (sum) 22fprintfTavlor series with fith first 4 non zero sums of sinx at x-l is Command Window Value Min 10f,eval (sum (1)) x7 symfun x1 symfun New to MATLAB? Watch this Video see Examples, or read Getting Started. sum x7 symfun 1x1 sym symbolic function inputs: x 乓Tay1。r serie with fith fir t 4 non zero sums of sinx at x-l is: 0.9092753117>> script Ln 22 Col 80 O Type here to search ENG 3:22 AM IN 08/31/18------------------------------------------------------Thank you-------------------------------------------------------

Add a comment
Know the answer?
Add Answer to:
Write a matlab program to apply Horner's algorithm to evaluate the sum of the first four...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a MATLAB script, which asks the user to input the angle xd (in deg) and...

    Write a MATLAB script, which asks the user to input the angle xd (in deg) and then approximates sine of the angle using the first 5 terms of Taylor series as follows: n+12n-1 sin n-1 (2n-1)! 1 Note that x in Taylor's equation is in radian, so make sure to do the conversion first Start with defining the vector n=1:5 and then use element-wise operation and basic MATLAB commands to calculate the summation. To calculate the factorial of any number,...

  • In Matlab Write a MATLAB program to calculate the sum of first 100 terms of the...

    In Matlab Write a MATLAB program to calculate the sum of first 100 terms of the following series: 1+()+()*+(3) + + ... + Hints: Here, n=100

  • 1.(10 points) Write a MATLAB program to calculate the sum of first 100 terms of the...

    1.(10 points) Write a MATLAB program to calculate the sum of first 100 terms of the following series: 100)*)* ...-) Hints: Here, n=100

  • photo of the code please and an explnation if possible, Construct a simple MATLAB function program...

    photo of the code please and an explnation if possible, Construct a simple MATLAB function program my_factorial which calculates product of first n positive integer numbers (i.e. find factorial n!). For full points: - Make sure you protect the code from illogical use (n must be positive integer) - Test the function by comparing with built in MATLAB function factorial(n) - Make sure you test your function for any limitations. O marks) -3. Using my factorial function from the previous...

  • MATLAB ONLY!! PLEASE WRITE IN COMPUTER SO I CAN COPY PASTE!!! ANSWER COMPLETELY, USE FOR LOOPS....

    MATLAB ONLY!! PLEASE WRITE IN COMPUTER SO I CAN COPY PASTE!!! ANSWER COMPLETELY, USE FOR LOOPS. THE PROGRAM TO BE MODIFIED IS THE NEXT ONE: clc clear % Approximate the value of e ^ x using the Taylor Series x = input( 'Enter the value of x for e^x. x = ' ); t = input( 'Enter the amount of desired terms. t = ' ); i = 1; e_taylor = 0; % initializing the variable for the accumulator while...

  • run/call tle un/cd to compute the sum of the first 15 terms of the series: th (b) It is desired 14 n3 - 20 n2 + 5n, 110) 1,2,..15 n Develop a pseudocode of the required program. roposed algorithm in...

    run/call tle un/cd to compute the sum of the first 15 terms of the series: th (b) It is desired 14 n3 - 20 n2 + 5n, 110) 1,2,..15 n Develop a pseudocode of the required program. roposed algorithm in a flow chart if it is solved using a for loop ow the p () Write a MATLAB script file using for loop run/call tle un/cd to compute the sum of the first 15 terms of the series: th (b)...

  • Consider making a function (mini program to complete a specific task) for each of the scenarios...

    Consider making a function (mini program to complete a specific task) for each of the scenarios below. State what the purpose of the function is in your own words, specify input that is needed by the function, what output is expected from the functions, and the step by step process that will obtain the output from the input (the algorithm). In addition to these 4 items also specify test data that can be used for each problem. Remember to describe...

  • Write a program that approximates the sum of this geometric series using a user- specified number...

    Write a program that approximates the sum of this geometric series using a user- specified number of terms. For example, if you named your program approx, calling approx(3) should use the first 3 terms of the series to calculate the approximation: Approximate result = 1/2 + 1/4 + 1/8 = 0.875... Note: the values are all powers of 1⁄2: (1/2)1, (1/2)2, (1/2)3, ... Next, have your program calculate the difference (rounded to 3 decimal places) between the value “1” and...

  • This is a matlab HW that I need the code for, if someone could help me figure this out it would b...

    This is a matlab HW that I need the code for, if someone could help me figure this out it would be appreciated. The value of t can be estimated from the following equation: in your script file, estimate the value of π for any number of terms. You must ask the user for the desired number of terms and calculate the absolute error/difference between your calculation and the built-in MATLAB value ofpi. Display your results with the following message...

  • Data clustering and the k means algorithm. However, I'm not able to list all of the...

    Data clustering and the k means algorithm. However, I'm not able to list all of the data sets but they include: ecoli.txt, glass.txt, ionoshpere.txt, iris_bezdek.txt, landsat.txt, letter_recognition.txt, segmentation.txt vehicle.txt, wine.txt and yeast.txt. Input: Your program should be non-interactive (that is, the program should not interact with the user by asking him/her explicit questions) and take the following command-line arguments: <F<K><I><T> <R>, where F: name of the data file K: number of clusters (positive integer greater than one) I: maximum number...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT