Erro in calling function in fsolve that has conditional operators

2 ビュー (過去 30 日間)
Shailee Yagnik
Shailee Yagnik 2019 年 9 月 4 日
コメント済み: Shailee Yagnik 2019 年 9 月 4 日
Here is my full code:
s1=4;
s2=1.2;
r=0.3;
t1=2.52;
tu=37; %limit for qfunc
v1=sqrt(1-r^2);
v2=r/v1;
v3=exp(-s2^2/2);
c1=t1/v1;
c2=(s1-r*s2)/v1;
x2d=(c1+tu)/v2;
x2n=x2d-c2/v2;
F1=ferror(x2d,x2n)
Error=fsolve(@(x2) F1,0)
function F1=ferror(x2d,x2n,x2)
%case 1 x2<x2n
if x2 < x2n
F1= v3.*exp(x2.*s2).*qfunc(-c1+v2.*x2)/qfunc(-c1+c2+x2.*v2);
% case 2 x2n<x2<x2d
else if x2n <= x2 & x2 <= x2d
F1 = -(v3.*exp(x2.*s2-(-c1+v2.*x2)^2/2))/(qfunc((-c1+c2+x2.*v2))*sqrt(2*pi)*(-c1+v2.*x2));
%case 3 x2>x2d
%
else
F1 = v3.*((-c1+c2+x2.*v2)/(-c1+v2.*x2)).*exp(-(-c1+v2.*x2)^2/2+(-c1+c2+x2.*v2)^2/2+x2.*s2);
end
end
end
If I run this it says undefined variable x2
please help.

採用された回答

Matt J
Matt J 2019 年 9 月 4 日
編集済み: Matt J 2019 年 9 月 4 日
Change these two lines,
%F1=ferror(x2d,x2n)
Error=fsolve(@(x2) ferror(x2d,x2n,x2),0)
Also, make sure to pass all variables that ferror() needs, like s2,c2, etc... or make ferror() a nested function.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSchedule Model Components についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by