How to plot an equation with two independent and one dependent variable?

조회 수: 4 (최근 30일)
Pragathi
Pragathi 2014년 1월 19일
댓글: Pragathi 2014년 1월 27일
p= 0.5 * ( (-1)^i * (w!/(i!*(w-i)!))*(1-(2*f*i)/w)^k-1)
where ∑ is between i=0 to w, f= w^2/(4*l), l=any prime number greater than 53, k varies between 1 to 100, w varies between 5 to 40.
i want to plot a graph 'k vs p' with w=fixed value eg.w=9
l=53 w=9 f= w^2/(4*l); for k=1:100 for i=0:w temp1=(-1)^i*nchoosek(w,i)*(1-(1-(2*f*i)/w)^k-1); temp(1,i+1)=temp1; end; temp2=0.5 * sum(temp); temp3(1,k)=temp2; end; plot(k,temp3);
though this code is not showing error the plot generated is wrong. the p values must be in the order of 10^-4 to 10^-12 for k ranging from 1 to 100.

채택된 답변

Amit
Amit 2014년 1월 19일
There is one difference between the equation and your code (however that does not fixes the issue though).
l=53;
w=30;
f= w^2/(4*l);
temp3 = zeros(1,100);
for k=1:100
temp = 0;
for i=0:w
temp1=((-1)^i)*(nchoosek(w,i))*((1-(2*f*i)/w)^k-1); % This line was different from the equation
temp= temp + temp1;
end;
temp3(1,k)=0.5 * temp;
end;
plot(1:100,temp3);
For small values of K, the order comes down to what you mentioned. Are you sure about the equation? or the values of K in which this order appear is 10 instead of 100?
  댓글 수: 1
Pragathi
Pragathi 2014년 1월 27일
Dear sir,
I think the difference you found between the code and the equation may be using nchoosek(w,i) line for (w!/(i!*(w-i)!)).If so, as far as i know i think both will give same answer.
The value of k varies between 1 to 100 but when i changed w=30 to w=9 and used semilogy in place of plot function in your answer i could get my plot (though it is not exact).
Thank you very much for the help.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Paul
Paul 2014년 1월 19일
it plots only points in vertical line because when you plot k has only a single value, namely 100. Add k=1:100; before the plot command, then it should plot what you want.

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by