Need matlab help!!!
Hi i'm taking an introductory course to matlab at Fau and i'm having a little trouble with my first project. Seeing as how this looks completely foreign to me, I have no clue what to do actually. I was wondering if someone could help me out. This is the project template:
Develop a computer program in MATLAB that will evaluate the following function for -0.9 ≤ x ≤ 0.9 in steps of 0.1 by:
A) an arithmetic statement .
B) by series allowing for as many as 50 terms. However, end adding terms when the last term only affects the 6th place in the answer.
The function and its series expansion is:
f(x)= (1+x^2)^.5= 1-1/2x^2 + 1/2 x 3/4x^4 - 1/2 x 3/4 x 5/6x^6 +-....
Print out a table (to a file) in the following format; use 6 decimal places for f(x).
X f(x)(by arith stm) f(x)(by series) ]
and there should be one last row that says # of terms used in the series
This program should be written off of these examples...
% Calculation of e^x by a Taylor series using a while loop. The 'input
% statement' is used to establish the exponent, x. A 'while loop' is
% used in determining the series solution. In this example term(n) is
% obtained by multiplying term(n-1) by x and dividing by the index n.
x=input('enter a value for the exponent x \n');
while abs(term) > ex*1.0e-6
if n > 50
If someone could at least tell me how to go about starting to write this program. I would be very appreciative.
% The program calculates of e^x by both an arithmetic statement (ex2)
% and by a Taylor series (ex1), where -0.5< x <0.5. A 'for loop' is
% used to determine the x values. In the series part of the program,
% the 'sum' function is used to sum all the terms calculated in the
% inner 'for loop'. Fifty terms are used in the series.
% Table headings
fprintf(' x ex1 ex2 \n');
fprintf('%5.2f %10.5f %10.5f \n',x,ex1,ex2);
P.s. I tried to get the appropriate spacings to translate over to this text box but it just wasn't having it.
Look at the examples. Load them and single step through in the debugger to get an idea of how they work.
Originally Posted by spikek1
Then change the calculation of the next term in the series from that in the examples to that for the function you have been asked for.
This is pretty much what i was able to write on my own today by comparing what i needed to result in and what the examples show.
fprintf(' x f(x)(my arith. statement) f(x)(by series) # of terms per series \n');
if (abs(term) <= 1.00e-6;
fprintf('%5.2f %10.6f %10.6f \n',x,ex2,ex1);
I don't know if i did this right... i'm not even sure if it's putting out the results my project is asking me to project... I also know that i need to "print" my results to a file which includes something like --- fid=fopen('output.dat','w'); and so on... but i'm not sure how to incorporate that. I also don't know how to set it up so i list the number of terms/ series in the last column. That part is completly beyond me too. My book is absolutely no help... I wish it was. but i've read the chapter three tiems and i'm still lost. HELP!!