User-defined Question output
Show older comments
Hi im trying to study for a quiz on user-defined functions. Im trying to run two expressions in one user-defined function and so far its only printing one set of values for each. Is there something wrong with the way im setting the user-defined function or the way im trying to print it out?
Function page:
function results=exfl(x)
term(1)=1.0;
for n=1:100
term(n+1)=(term(n))*((-1^n)*((x).^(2))*(2*n-1)/(2*n));
if abs(term(n+1))<=1.0e-7
break
end
end
ex1=sum(term);
for i=1:length(x)
f=(1+x(i)^2)^(-0.5);
end
ex2=sum(f);
results=[ex1',ex2'];
and the next script page:
clc;
fprintf(' x fx(arithmetic) fx(series)\n');
fprintf('-----------------------------------\n');
x=-.9:.1:.9;
%We must set x as a function of i for the for loop
for i=length(x)
y=exfl(x(i));
fprintf(' %.1f %10.6f %10.6f \n',x(i),y);
end
any advice or tips would be greatly appreciated!
Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!