フィルターのクリア

Unable to plot after using fsolve

1 回表示 (過去 30 日間)
jayash
jayash 2015 年 5 月 7 日
回答済み: lei kai 2015 年 5 月 8 日
Ut=0;
while Ut<20
cn = @(q1,q2,n0)((Ut.*n0)./(1-cos(2.*pi.*q1)-cos(2.*pi.*q2)));
y = @(q1,q2,n0)0.25.*((1+cn(q1,q2,n0)).^(-1/2)+(1+cn(q1,q2,n0)).^(1/2)-2);
a = -0.5;
b = 0.5;
v = @(n0) (quad2d(@(q1,q2) y(q1,q2,n0),a,b,a,b));
cv =@(n0) n0+(0.5*v(n0))-1;
x0 = 0.1;
n = fzero(cv,x0);
plot(Ut,n,'*')
xlabel('U/t')
ylabel('n0/n')
hold on
Ut = Ut + 1;
end
The plot should be similar looking like y=1/x but I am only getting a point. Anybody please help me out.

回答 (2 件)

Walter Roberson
Walter Roberson 2015 年 5 月 8 日
You forgot to tell us that you also get some output, namely
Warning: Reached the maximum number of function evaluations (2000). The result fails the global error test.
> In quad2d at 244
In @(n0)(quad2d(@(q1,q2)y(q1,q2,n0),a,b,a,b))
In @(n0)n0+(0.5*v(n0))-1
In fzero at 286
Error using fzero (line 309)
Function value at starting guess must be finite and real.
That happens when Ut = 1 (the second iteration). The integration is failing. Are you sure the integral converges?

lei kai
lei kai 2015 年 5 月 8 日
there is something wrong with your function cv,when Ut=1,n = fzero(cv,x0);will error

カテゴリ

Help Center および File ExchangeOptimization についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by