フィルターのクリア

problem with command solve inside a function.

1 回表示 (過去 30 日間)
Sasi
Sasi 2012 年 2 月 14 日
Hi I have a problem using command solve in a function. My codes are:
function [a]=test(ka,landa)
sym x
y = (ka/landa)*((x/landa)^(ka-1))* (2^(-(x/landa)^ka));
LO = diff(y);
sf=solve(LO,x);
tt=length(sf);
if(tt>1)
a= double(sf(2));
end;
if(tt ==1)
a=double(sf(1));
end;
end
when I run this function with test(2.22,0.90), I get the answer 0.81 and tt=4, but when I call this function in another function I got 0 and the tt=1.
could you please help me with this? by the way I use MATLAB R2011a.
tanx
sasi

採用された回答

Andrew Newell
Andrew Newell 2012 年 2 月 14 日
When I try running this function
function [a,tt] = runtest(ka,landa)
[a,tt] = test(ka,landa);
I get the same answer for both of the following commands:
[a,tt] = test(ka,landa)
[a,tt] = runtest(ka,landa)
(after fixing the top line of the function, which should be syms x).

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by