Symbol calculation and numerical values
16 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Pouyan Msgn
il 12 Lug 2019
Commentato: John D'Errico
il 14 Lug 2019
Hi!
I have my code here :
clc
clear all
syms k w m e s
eqn=k==[w*sqrt(e*m/2)*sqrt(sqrt(1+(s/(w*e))^2)-1)]
k=1; e=0.0006; m=2000; w=2*pi*10^6;
sol=solve(eqn,s)
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?
0 Commenti
Risposta accettata
John D'Errico
il 12 Lug 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;
fplot(eqn,[-.1,.1])
yline(0);
grid on
I've plotted it over a fairly small domain. It does cross the line at y==0.
ssol = solve(eqn,s)
ssol =
-(1288490188800*pi*3^(1/2)*18206206649565666255441706068998^(1/2))/27309309974347922922410255680009
(1288490188800*pi*3^(1/2)*18206206649565666255441706068998^(1/2))/27309309974347922922410255680009
vpa(ssol)
ans =
-0.0010954451150103438340309550004199
0.0010954451150103438340309550004199
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
2 Commenti
John D'Errico
il 14 Lug 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?
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!