Solve function not working?
15 ビュー (過去 30 日間)
古いコメントを表示
Well here my code:
clear all
clear vars
syms x y
y=1+(x).^(2)
x=-1
a=subs(y)
x=3
b=subs(y)
c=(b-a)./(4)
yy=diff(y)
disp(yy)
ans=solve(yy==c,x)
disp(ans)
And according to me 2x=2 and hence x=1 therefore a solution must exist but the output is Empty sym: 0-by-1
0 件のコメント
採用された回答
Walter Roberson
2018 年 10 月 18 日
編集済み: Walter Roberson
2018 年 10 月 18 日
You have
x=3
so when you do
ans=solve(yy==c,x)
that is the same as
ans=solve(yy==c,3)
and 3 is never equal to 0, so the system is unsolvable.
I recommend that you avoid this problem in future by never assigning a value to a symbolic variable that has been used in an expression -- not unless you proceed to immediately overwrite the expression with the new variation on the variable. Use the three-parameter version of subs() instead.
x1=-1
a=subs(y,x,x1)
x2=3
b=subs(y,x,x2)
Now x is still a symbolic variable.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Calculus についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!