Question

Hello! i need help with a problem in this textbook, Essential MATLAB, 6th edition. Question 8.11:...

Hello! i need help with a problem in this textbook, Essential MATLAB, 6th edition. Question 8.11:

Use the Taylor Series,

cosx=1- (x2/2!)+(x4/4!)-(x6/6!)+.........

To write a program to compute cosx correct to 4 decimal places )x is in radians). see how many terms are needed to get 4 figure agreement with the MATLAB function cos. Dont make x too large; that could cause rounding errors.

I can get an out put correct up to about only 10 radians, but then it becomes way off, This is what i have:

function cosx = cosx(x)
i=2;
a=1;
while a>0.001
a=((x^i)/(factorial(i)))*(-1);
i=i+2;

end
a=a+1
end

Thank you!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE:

function a = cosx(x)
    i = 0;
    a = 0;
    while abs(a - cos(x)) > 0.0001
        a = a + (x^i/factorial(i))*(-1)^(i/2);
        i = i + 2;
    end
end

SAMPLE OUTPUT:

FOR ANY HELP JUST DROP A COMMENT

Add a comment
Know the answer?
Add Answer to:
Hello! i need help with a problem in this textbook, Essential MATLAB, 6th edition. Question 8.11:...
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
  • Hello, I need help with the following question in MATLAB for digital image processing, thank you ...

    Hello, I need help with the following question in MATLAB for digital image processing, thank you for your help in advance Convolution operations using mask are commonly applied in image enhancement. Even edge detection is based on convolution with a specially designed mask. The assignment here is to write your own function for convolution and test it in edge detection. 1. Write a function in Matlab as follows: function Img2 Convolution(Img, mask); %Input: Img is the original image data matrix,...

  • I'm trying to solve this problem by using matlab. But I don't know reason why I can't get the solutions. I w...

    I'm trying to solve this problem by using matlab. But I don't know reason why I can't get the solutions. I wanna get a plot of this differential equation. Please find a way how to solve this problem. May there're errors in the code. Please check it.    second-oder-ode2.m x 曱function, second-oder-ode2 t=0:0.001 :30; initial-× = 0; in i t i al-dxdt 0; lt,影=ode45( @rhs, t. [initial.x initial-dxdt ] ); plot( (:, 1) ) ; xlabel( 't); ylabel(): function dxdt=rhs( t,...

  • Hello. I need help modifying this MatLab code. This is a basic slider-crank animation. the current...

    Hello. I need help modifying this MatLab code. This is a basic slider-crank animation. the current program stops the animation and then has the crank move backward. I need the crank to instead to move in full 360 degrees circular motion. Exactly like how a slide-crank mechanism works in real life. thank you and here is the code. %%Code Begins Here%% L1=0.2; L2=0.45; W=0.5; tt=linspace(0,15); for i=1:length(tt)     x2=@(t) L2+L1*sin(W*t);     y2=0;     X2=x2(tt(i));     Y2=y2;     sol= fsolve(@(x,x2,y2) root2d(x,X2,Y2),...

  • I'm trying to solve this differential equations by using matlab. But I don't know the reason why I can't ge...

    I'm trying to solve this differential equations by using matlab. But I don't know the reason why I can't get the solutions. I've attached matlab code and few differential equation. Please find a the way to solve this problem. second oder ode2.m x+ function, second-oder-ode2 t-0:0.001:30 initial-x = 0; initial-dxdt = 0: lt.影=ode45( @rhs, t, [initial.x initial.dxdt ] ); plot(t.(:,1l): xlabel( t); ylabel(x): 申 function dxdt=rhs( t, x) dxdt-1 =x(2); dxdt-2 (-50 x(2)+61.25+((1-cos(4 pi 10 t))/2) (47380 x(1)-3-7428 x(1) 2...

  • Hello, can you do this in matlab full solution thanks Purpose: To practice using the MatLab...

    Hello, can you do this in matlab full solution thanks Purpose: To practice using the MatLab interface. practice with Matrix Arithmetic Operation. Degree of Difficulty: Easy After the fourth shinobi world war, it becomes a rule in Konoha that to be a jenin (the lowest level of ninja) from an academic student (ninja-student) anyone needs to get 1000 points. A student can earn points by finishing different missions. Below is a chart showing the individual mission points based on the...

  • Montgomery & Runger, Applied Statistics and Probability for Engineers, 6th Edition Help I System ...

    Montgomery & Runger, Applied Statistics and Probability for Engineers, 6th Edition Help I System Announcements nment An artide in Technometrics by s. C. Narula and J. F. Wellington ("Prediction, Linear Regression, annual taxes (x) for 24 houses. The taxes indude local, school and county taxes. The data are shown in the following table. PRINTER VERSTON 4BACK NEXT and a Minimum Sum of Relative Errors," Vol. 19, 1977) presents data on the selling price (V) and Sale Price/1000 Taxes/1000 25.9 29.5...

  • MATLAB only please I am trying to get my getdatafuntion to work. I am also trying to get all my x...

    MATLAB only please I am trying to get my getdatafuntion to work. I am also trying to get all my x's, y's, and v's to popup in the command window so I can put in any value and it will find the value for me using the equation I put in. function project_9_sjl() % PROJECT_9_SJL project_9_sjl() is the driver function for the program. % %    Name: Scott Lawrence %   Date: 3/27/2019 %   Class: CMPSC 200 %   Description: Determine the optimal...

  • Matlab While loop help I'm doing a random walk problem and i need to make it...

    Matlab While loop help I'm doing a random walk problem and i need to make it so that when the walker goes over a certain position it gets reflected back onto the center (position=0). For this I'm trying to use while loops but they seem to get stuck. The program works fine until it reaches one of its limits (-10 or 10) then the while loops are supposed to prevent the position from going further and instead send the position...

  • Matlab fprintf help This is the question: I have already done part a, I need help...

    Matlab fprintf help This is the question: I have already done part a, I need help with part b. This is my current code: % array of Pounds to convert to Kilograms weight_pound = [50.543 65.676 75.343 80.937] % for Loop that calls from the array weight_pounds for index=1:4 %Convert weight from Pounds to Kilograms     weight_kg = weight_pound*0.453592 %Print out the conversion % ‘%5.2f’ for 2 decimals for Kilograms % ’%5.0f’ for no decimals in pounds     fprintf(‘%5.2f kg...

  • Hello I need help with python programming here is my code # Trivia Challenge # Trivia...

    Hello I need help with python programming here is my code # Trivia Challenge # Trivia game that reads a plain text file import sys def open_file(file_name, mode): """Open a file.""" try: the_file = open(file_name, mode) except IOError as e: print("Unable to open the file", file_name, "Ending program.\n", e) input("\n\nPress the enter key to exit.") sys.exit() else: return the_file def next_line(the_file): """Return next line from the trivia file, formatted.""" line = the_file.readline() line = line.replace("/", "\n") return line def next_block(the_file):...

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
ADVERTISEMENT