Using If for syms
1 回表示 (過去 30 日間)
古いコメントを表示
Hi,
I hope you are keeping safe.
I have a urgent question in matlab. Could you please give me sime advice in this regard. I wrote following code where
"function F = fun(x,y,alpha1,alpha2,beta1,beta2,lambda)
F= log((1+alpha1*x./(1+alpha2*y))) -lambda*log((1+beta1*x./(1+beta2*y)));
end"
Main Code
Z=fun(x,P-x,alpha1,alpha2,beta1,beta2,lambda);
z=solve(Z==0);
for i=1:length(z)
z(i,1)=piecewise(z(i,1)<=0,0)
y(i)=P-z(i,1)
S(i)=fun(z(i,1),y(i),alpha1,alpha2,beta1,beta2,lambda)
end
I want to z(i,1)=0 if z(i,1)<=0 or complex and if z(i,1)>0, claculate S(i) but there is a problem with piecewise() which cannot be solved for me.
Could you please help me to write it. P, alpha1, alpha2, beta1, beta2, and lambda are desired positive valuse.
Many Thanks in advance.
0 件のコメント
回答 (1 件)
Walter Roberson
2021 年 3 月 6 日
subs(piecewise(x<3,0),x,5)
ans = NaN
That is, if no condition is matched by the piecewise then the output is undefined, NaN. Not 0 or empty.
piecewise(imag(z(i))~=0 || z(i)<0, 0, S(i))
6 件のコメント
参考
カテゴリ
Help Center および File Exchange で Function Creation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!