Symbol calculation and numerical values

22 views (last 30 days)
I have my code here :
clear all
syms k w m e s
k=1; e=0.0006; m=2000; w=2*pi*10^6;
It will solve s for me, but if I want now a value for s, how should I do that? I do not just want to have S as a symbol, but when I have values for other parameters S must also get a numeric value. How can I do this in Matlab?

Accepted Answer

John D'Errico
John D'Errico on 12 Jul 2019
You are doing things in the wrong order.
k,e,m,w are not unknowns. They are knowns. So why have you set them up as symbolic?
Next, subtract k from the right hand side. Don't set the two equal. This lets you plot the thing. ALWAYS PLOT EVERYTHING! Do that before you just throw it into a solver.
syms s
k=1; e=0.0006; m=2000; w=2*pi*10^6;
eqn = (w*sqrt(e*m/2)*sqrt(sqrt(1+(s/(w*e))^2)-1)) - k;
grid on
I've plotted it over a fairly small domain. It does cross the line at y==0.
ssol = solve(eqn,s)
ssol =
ans =
Yes, you could have set everything up as symbolic, then substitute the values of k,e,m,w in at the end.
syms k w m e s
eqn = (w*sqrt(e*m/2)*sqrt(sqrt(1+(s/(w*e))^2)-1)) - k
eqn =
w*((s^2/(e^2*w^2) + 1)^(1/2) - 1)^(1/2)*((e*m)/2)^(1/2) - k
ssol = solve(eqn,s)
ssol =
-(2*k*(k^2 + e*m*w^2)^(1/2))/(m*w)
(2*k*(k^2 + e*m*w^2)^(1/2))/(m*w)
So then read the help for subs.
help subs
John D'Errico
John D'Errico on 14 Jul 2019
But I showed you how to solve it directly, two different ways.
You can leave those variables as symbolic, then use solve as I did. Then use subs, as I told you to do, substituting in the values for k,e,m,w.
Or you can set those values as constants first, then solve for s. Either way works. So what is the problem?

Sign in to comment.

More Answers (0)


Community Treasure Hunt

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

Start Hunting!