How do I plot this data set like this image?
Afficher commentaires plus anciens
So I have a function:
function [ xs ] = myExpFunction(x)
xs=zeros(1,length(x));
xl=zeros(51,length(x)); %preallocation of the storage
for n= 0:50
xt = ((x.^n)/factorial(n));
if xt(xt <0.01)
xt(xt <0.01)=0;
end
xl(n+1,:) = xt
end
for ii = 1:length(x)
xs(ii)=sum(xl(:,ii)) ; %calculate the sum of the iteration results
end
end
And at this line:
xl(n+1,:) = xt
@ x= [1 2 3 4 5]
Gives out:
xl =
1.0000 1.0000 1.0000 1.0000 1.0000
1.0000 2.0000 3.0000 4.0000 5.0000
0.5000 2.0000 4.5000 8.0000 12.5000
0.1667 1.3333 4.5000 10.6667 20.8333
0.0417 0.6667 3.3750 10.6667 26.0417
0 0.2667 2.0250 8.5333 26.0417
0 0.0889 1.0125 5.6889 21.7014
0 0.0254 0.4339 3.2508 15.5010
0 0 0.1627 1.6254 9.6881
0 0 0.0542 0.7224 5.3823
0 0 0.0163 0.2890 2.6911
0 0 0 0.1051 1.2232
0 0 0 0.0350 0.5097
0 0 0 0.0108 0.1960
0 0 0 0 0.0700
0 0 0 0 0.0233
My task is to create some code in the function to add up the numbers per iteration and plot them against x. i.e. at n=0, there will just be a line through y=1, but at n=1, y=[2 3 4 5 6] where the 1st row adds to the 2nd row. How do I do this!? Please help :(

%
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
