Subs not working for symbolic expressions

7 ビュー (過去 30 日間)
Matthew Thomas
Matthew Thomas 2018 年 2 月 2 日
コメント済み: Jes Bel 2018 年 7 月 13 日
I have the following code and want to evaluate s at x(1) and y(1) and store it to s in s(1). The expression worked fine when I was using
s1 = (fun,{x,y},{x1,y1});
I'm unsure why the following code is failing to run?
A = 39.3;
B = 19.7;
t = 0.1;
syms x y
pxysym = A*x-3*x^2-4*x*y;
qxysym = B*y-2*x*y-y^2;
pxsym = diff(pxysym,x);
pysym = diff(pxysym,y);
qxsym = diff(qxysym,x);
qysym = diff(qxysym,y);
sxsym = pxysym*pxsym+qxysym*qxsym;
sysym = pxysym*pysym+qxysym*qysym;
x = zeros();
y=zeros();
x(1) = 5
y(1) = 5
ssym=0.5*(pxysym^2+qxysym^2);
s(1) = subs(ssym,{x,y},{x(1),y(1)})
TIA
  1 件のコメント
Jes Bel
Jes Bel 2018 年 7 月 13 日
I think you need [] instead of {} with subs

サインインしてコメントする。

採用された回答

Steven Lord
Steven Lord 2018 年 2 月 2 日
Look at the output of the following command executed immediately before your subs call.
whos
Is x a symbolic variable at that point? What in your symbolic expression is your subs call actually trying to replace?
I would change the name of the variable containing the numeric values you want to substitute into your symbolic expression to something else, like "xx = 5". Then substitute the value of xx for the symbolic variable x.

その他の回答 (0 件)

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by