Projects P3,1 Develop a computer program in MATLAB that will evaluate the follow
ID: 1716683 • Letter: P
Question
Projects P3,1 Develop a computer program in MATLAB that will evaluate the following functions for -0.9 3x s0.9 in steps of 0.1 by a. An arithmetic statement. b. A series allowing for as many as 50 terms. However, stop adding terms when the last term only affects the 6th decimal place in the answer. c. Print to a file a table similar to Table P3.1 with fx) to 6 decimal places. The functions and their series expansions are x 1.1:3.5 2 2.4 2.4.6 2.4.6.8 2.f(x) = (1 + x)-1/2=1-2x+1.3x2-1-3-5x3+13.57 x4 132 1.3-5 1 13 2 2.4x -2.4.6x 1.3.5.7 2-4-6-8 Table P3.1 Template for Output Table f(x) (By Series) # of Terms Used in the Series f(x) (By Arithmetic Statement) 0.9 -0.8 -0.7 0.7 0.8 0.9Explanation / Answer
the four functions are below
function 1;
%project 3.1
clear
i=0;
k=0;
fprintf('%5s %10s %10s %7s ','x','arithm','series','#term')
for x=-0.9:0.1:0.9
k=0;
fx_k=1;
errterm=2;
i=i+1;
term_k=1;
%a1.f(x)=(1+x)^(0.5)
fxa=(1+x)^(0.5);
%b1.Serie
while errterm>1
k=k+1;
term_k=term_k*(3/(2*k)-1)*x;
fx_k=fx_k+term_k;
errterm=abs((term_k)*1000000);
if k==50
errterm=0.1;
end
end
%c1.table
tfx(i,:)=[fxa,fx_k,k];
formats='%5.1f %10.6f %10.6f %5.0f ';
fprintf(formats,x,fxa,fx_k,k)
end
x arithm series #term
-0.9 3.162278 3.158880 50
-0.8 2.236068 2.236064 50
-0.7 1.825742 1.825740 33
-0.6 1.581139 1.581138 23
-0.5 1.414214 1.414213 18
-0.4 1.290994 1.290994 14
-0.3 1.195229 1.195228 11
-0.2 1.118034 1.118034 8
-0.1 1.054093 1.054093 6
0.0 1.000000 1.000000 1
0.1 0.953463 0.953463 6
0.2 0.912871 0.912871 8
0.3 0.877058 0.877058 11
0.4 0.845154 0.845154 14
0.5 0.816497 0.816497 18
0.6 0.790569 0.790569 23
0.7 0.766965 0.766965 33
0.8 0.745356 0.745356 50
0.9 0.725476 0.725670 50
function 2;
%project 3.1
clear
i=0;
k=0;
fprintf('%5s %10s %10s %7s ','x','arithm','series','#term')
for x=-0.9:0.1:0.9
k=0;
fx_k=1;
errterm=2;
i=i+1;
term_k=1;
%a2.f(x)=(1+x)^(-0.5)
fxa=(1+x)^(-0.5);
%b2.Serie
while errterm>1
k=k+1;
term_k=term_k*(1/(2*k)-1)*x;
fx_k=fx_k+term_k;
errterm=abs((term_k)*1000000);
if k==50
errterm=0.1;
end
end
%c2.table
tfx(i,:)=[fxa,fx_k,k];
formats='%5.1f %10.6f %10.6f %5.0f ';
fprintf(formats,x,fxa,fx_k,k)
end
x arithm series #term
-0.9 0.316228 0.316257 50
-0.8 0.447214 0.447217 33
-0.7 0.547723 0.547724 23
-0.6 0.632456 0.632456 17
-0.5 0.707107 0.707107 13
-0.4 0.774597 0.774597 10
-0.3 0.836660 0.836660 8
-0.2 0.894427 0.894427 7
-0.1 0.948683 0.948683 5
0.0 1.000000 1.000000 1
0.1 1.048809 1.048809 5
0.2 1.095445 1.095445 7
0.3 1.140175 1.140175 8
0.4 1.183216 1.183216 10
0.5 1.224745 1.224745 13
0.6 1.264911 1.264911 17
0.7 1.303840 1.303841 23
0.8 1.341641 1.341641 33
0.9 1.378405 1.378403 50
function 3;
%project 3.1
clear
i=0;
k=0;
fprintf('%5s %10s %10s %7s ','x','arithm','series','#term')
for x=-0.9:0.1:0.9
k=0;
fx_k=1;
errterm=2;
i=i+1;
term_k=1;
%a3.f(x)=(1+x^2)^(-0.5)
fxa=(1+x^2)^(-0.5);
%b3.Serie
while errterm>1
k=k+1;
term_k=term_k*(1/(2*k)-1)*x^2;
fx_k=fx_k+term_k;
errterm=abs((term_k)*1000000);
if k==50
errterm=0.1;
end
end
%c3.table
tfx(i,:)=[fxa,fx_k,k];
formats='%5.1f %10.6f %10.6f %5.0f ';
fprintf(formats,x,fxa,fx_k,k)
end
x arithm series #term
-0.9 0.743294 0.743295 50
-0.8 0.780869 0.780869 27
-0.7 0.819232 0.819232 17
-0.6 0.857493 0.857493 12
-0.5 0.894427 0.894427 9
-0.4 0.928477 0.928477 7
-0.3 0.957826 0.957826 6
-0.2 0.980581 0.980581 4
-0.1 0.995037 0.995037 3
0.0 1.000000 1.000000 1
0.1 0.995037 0.995037 3
0.2 0.980581 0.980581 4
0.3 0.957826 0.957826 6
0.4 0.928477 0.928477 7
0.5 0.894427 0.894427 9
0.6 0.857493 0.857493 12
0.7 0.819232 0.819232 17
0.8 0.780869 0.780869 27
0.9 0.743294 0.743295 50
function 4;
%project 3.1
clear
i=0;
k=0;
fprintf('%5s %10s %10s %7s ','x','arithm','series','#term')
for x=-0.9:0.1:0.9
k=0;
fx_k=1;
errterm=2;
i=i+1;
term_k=1;
%a4.f(x)=(1+x)^(1/3)
fxa=(1+x)^(1/3);
%b4.Serie
while errterm>1
k=k+1;
term_k=term_k*(1/3-k+1)*x/k;
fx_k=fx_k+term_k;
errterm=abs((term_k)*1000000);
if k==50
errterm=0.1;
end
end
%c4.table
tfx(i,:)=[fxa,fx_k,k];
formats='%5.1f %10.6f %10.6f %5.0f ';
fprintf(formats,x,fxa,fx_k,k)
end
x arithm series #term
-0.9 0.464159 0.464209 50
-0.8 0.584804 0.584807 35
-0.7 0.669433 0.669434 24
-0.6 0.736806 0.736808 17
-0.5 0.793701 0.793701 14
-0.4 0.843433 0.843433 11
-0.3 0.887904 0.887904 9
-0.2 0.928318 0.928318 7
-0.1 0.965489 0.965489 5
0.0 1.000000 1.000000 1
0.1 1.032280 1.032280 5
0.2 1.062659 1.062659 7
0.3 1.091393 1.091393 9
0.4 1.118689 1.118689 11
0.5 1.144714 1.144714 14
0.6 1.169607 1.169607 17
0.7 1.193483 1.193483 24
0.8 1.216440 1.216441 35
0.9 1.238562 1.238559 50
response to comment
the problem is the four functions. for one functions the code is:
%project 3.1
clear
i=0;
k=0;
fprintf('%5s %10s %10s %7s ','x','arithm','series','#term')
for x=-0.9:0.1:0.9
k=0;
fx_k=1;
errterm=2;
i=i+1;
term_k=1;
%a1.f(x)=(1+x)^(0.5)
fxa=(1+x)^(0.5);
%b1.Serie
while errterm>1
k=k+1;
term_k=term_k*(3/(2*k)-1)*x;
fx_k=fx_k+term_k;
errterm=abs((term_k)*1000000);
if k==50
errterm=0.1;
end
end
%c1.table
tfx(i,:)=[fxa,fx_k,k];
formats='%5.1f %10.6f %10.6f %5.0f ';
fprintf(formats,x,fxa,fx_k,k)
end
the only difference between the four functions are:
term_k and fxa
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.