% Problem : First'for' loop will run four time. Each time z(n+1) will have % four different values.I want to plot this z(n+1) values for different % value of y. ( Y range can be 0.63095:3.98107) for y=0.63095:3.98107 B=0.5.*(1-​sqrt(y./(1​+y)));

Question relating to plotting

2 commentaires

naina - please show your code so that we can understand what the first for loop is. Are you trying to plot something on each iteration of the loop? Is there a second for loop?
% Problem : First'for' loop will run four time. Each time z(n+1) will have
% four different values.I want to plot this z(n+1) values for different
% value of y. ( Y range can be 0.63095:3.98107)
for y=0.63095:3.98107
B=0.5.*(1-sqrt(y./(1+y)));
P=[ 0 0 0 0 0 0.0020 0.0134 0.0523 0.1498 0.3479 0.6496 0.9156 0.9968 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1];
for n=1:32
z(1)=0;
z(n+1)=((factorial(32))./(factorial(n).*(factorial(32-n))).*(B.^(n)).*((1-B).^(32-n)).*(P(n)));
z(n+1)=z(n)+z(n+1);
end
z(n+1) % This will have four different values as first 'for' loop will run four time
end

Réponses (1)

naina - I suspect that you want to make z a 4x33 matrix
z = zeros(4,33);
k = 1;
for y=0.63095:3.98107
B=0.5.*(1-sqrt(y./(1+y)));
P=[ 0 0 0 0 0 0.0020 0.0134 0.0523 0.1498 0.3479 0.6496 0.9156 0.9968 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1];
z(k,1)=0;
for n=1:32
z(k,n+1)=((factorial(32))./(factorial(n).*(factorial(32-n))).*(B.^(n)).*((1-B).^(32-n)).*(P(n)));
z(k,n+1)=z(k,n)+z(k,n+1);
end
k = k + 1;
end

Cette question est clôturée.

Clôturé :

le 20 Août 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by