syms back to numbers

I am using syms to calculate equations with derivatives. I need to assign these syms number values to complete the analysis.
syms x y z
f=x^3 - 2 * y^4 + 4 * z^2
x=4
y=3
z=5
f=

Answers (1)

Use subs to substitute the values in:
syms x y z
f=x^3 - 2 * y^4 + 4 * z^2
subs(f,{x,y,z},{4,3,5})
And

6 Comments

Philosophaie
Philosophaie on 4 Feb 2014
Edited: Philosophaie on 4 Feb 2014
subs(f,{x,y,z},{4,3,5})
does not work if " f " is a 4x4, a 4x4x4 or a 4x4x4x4 array
huh?
Please provide a minimal working example.
syms r h p t
m=constant
g_ = [1/(1-2*m/r) 0 0 0;0 r^2 0 0;0 0 r^2*(sin(h))^2,0;0,0,0,-(1-2*m/r)]
rr = exlSheet1.Range(['C' num2str(5)]).value;
theta = exlSheet1.Range(['D' num2str(5)]).value;
phi = exlSheet1.Range(['E' num2str(5)]).value;
tt = exlSheet1.Range(['F' num2str(5)]).value;
subs(g_,{r,h,p,t},{rr,theta,phi,tt})
There does not appear to be any "p" or "t" in your g_ ?
What values are you extracting for the variables, and what result do you get for the substitution, and what result are you expecting for the substitution ?
Actually g_ did evaluate correctly, a 4x4.
The problem came in Affinity, a 4x4x4 with an error code:
??? Error using ==> maple
Error, (in index/FillInitVals) array defined with 1 indices, used with 3 indices
Error in ==> sym.subs at 229
NEWf = sym(maple('evalm',strrep(NEWf,'MATRIX','array')));
Error in ==> SchwarzchildAnalysis_Excel>Evaluate at 65
subs(Affinity,{r,h,p,t},{rr,theta,phi,tt})
What does Affinity look like before substitution? And please cross-check that rr, theta, phi, and tt are all scalars.

Sign in to comment.

Asked:

on 4 Feb 2014

Commented:

on 5 Feb 2014

Community Treasure Hunt

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

Start Hunting!