Symbol calculation and numerical values
조회 수: 20 (최근 30일)
이전 댓글 표시
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
채택된 답변
John D'Errico
2019년 7월 12일
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
John D'Errico
2019년 7월 14일
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?
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!