Subs function not working as expected

조회 수: 1 (최근 30일)
Patricio Whittingslow
Patricio Whittingslow 2018년 9월 25일
댓글: Patricio Whittingslow 2018년 9월 25일
I've come across an unexpected result. Symbolic equation substitution is yielding wrong result. Below is my code.I've tried reset(symengine) but it doesen't seem to help.
syms y real
Tsym = ...
(204800*y)/7 - (19342813113834066795298816*y^2)/661131307601750375 + 60;
Tfunc=@(y) ...
(204800*y)/7 - (19342813113834066795298816*y^2)/661131307601750375 + 60;
H=0.0005;
y=H;
symval=subs(Tsym);
funcval=Tfunc(H);
if funcval~=symval
fprintf('Something is wrong. \n')
end

답변 (1개)

Bish Erbas
Bish Erbas 2018년 9월 25일
Code below works for me. You defined the H and y variables after defining the symbolic equations. Move the variable definition at the beginning of your code.
syms y real
H=0.0005;
y=H;
Tsym = ...
(204800*y)/7 - (19342813113834066795298816*y^2)/661131307601750375 + 60;
Tfunc=@(y) ...
(204800*y)/7 - (19342813113834066795298816*y^2)/661131307601750375 + 60;
symval=subs(Tsym);
funcval=Tfunc(H);
if funcval~=symval
fprintf('Something is wrong. \n')
end
  댓글 수: 1
Patricio Whittingslow
Patricio Whittingslow 2018년 9월 25일
Hey there Bish! It seems your solution does return the correct value. However, I lose the symbolic function in the process. Tsymb (the equation is now equal to a value, not an equation). What's the best practice to use subs if I want to continue evaluating the same function for N values of y?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Assumptions에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by