Subs function does not work on symbolic expressions and functions

9 Ansichten (letzte 30 Tage)
Hi, I would like to ask about a problem when using subs function on a syms variable. Below is my code.
I don't know why but in the subs function, I cannot replace the m variable in v with numeric value of mVal (which mVal = m = 25*2^(1/2)*17^(1/2))/108 after solving).
So when I run the code, the output MagV = (850/abs(m)^2)^(1/2) which is a function of m, instead of an actual numeric value.
How can I replace mVal to m, and get the actual numeric value of MagV, instead of a function of m?
syms m t v(t)
v =[(5*t)/m, (3*t)/m, 0]
m = solve(norm([5/m, 3/m, 0]) == 4.32, m);
mVal = m;
MagV = norm(subs(v, [t m], [5 mVal])); MagV

Akzeptierte Antwort

Ameer Hamza
Ameer Hamza am 29 Mai 2020
You are overwriting the symbolic variable 'm' with numeric value on line
m = solve(norm([5/m, 3/m, 0]) == 4.32, m);
and after that, subs() no longer recognize m as the symbolic variable. Try the following code with a line removed from your code
syms m t v(t)
v =[(5*t)/m, (3*t)/m, 0];
mVal = solve(norm([5/m, 3/m, 0]) == 4.32, m);
MagV = norm(subs(v, [t m], [5 mVal]));
MagV
  1 Kommentar
Nhat Huy Tran Huu
Nhat Huy Tran Huu am 1 Jun. 2020
Thank you so much for your answer. Actually I have to keep the symbolic variable m, because I am using Matlab Grader in class course, and the problem requires me to submit answer to variable m.
Anyway, it works. Thank you so much.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Symbolic Math Toolbox finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by