The difference between using and not using '' in the solve() function
1 次查看(过去 30 天)
显示 更早的评论
what is The difference between using and not using '' in the solve() function?
and should we use '' ?
codes are as this
clc;
clear all;
close all;
syms x;
syms a b c;
solution1=solve(a*x^2+b*x+c==0,x)
solution2=solve(a*x^2+b*x+c==0,'x')
solution3=solve('a*x^2+b*x+c==0','x')
equation=a*x^2+b*x+c==0;
solution4=solve(equation,'x')
solution5=solve(equation,x)
solution6=solve('equation',x)
0 个评论
采纳的回答
Walter Roberson
2019-5-14
In current versions of solve(), quoted strings are only permitted as name/value pairs.
In your older version of MATLAB, quoted strings represented (almost) MuPAD code -- except with () indexing instead of [] indexing, and with == permited as well as = .
solve(a*x^2+b*x+c==0,'x')
meant to look in the MATLAB workspace to find the current values of a, b, and c, and to construct an equation from whatever values it found there. Any symbolic variable that was encountered would be internally replaced with an internal name such as _symans_[[32,0,2038]] that is the address of the variable in the symbolic engine -- an address that might be associated with a completely different name. The various items like these would be put together in a character vector that would be submitted to the symbolic engine for execution. The symbolic engine, instead of receiving x^2, might receive something like
evalin(symengine, '_power(_symans_[[32,0,2038]], 2)')
However,
solve('a*x^2+b*x+c==0','x')
would simply be transformed to
evalin(symengine, 'solve(a*x^2+b*x+c=0, x)')
This would not use whatever a, b, c values that were in the workspace: it would rely upon whatever value for a, b, c happened to exist in the symbolic engine, which would not generally be referring to the same name/value association as at the MATLAB level.
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!