How do I get normal numerical answers using solve or vpasolve?

I'm currently making a function within which I determine a Reflectivity value by solving the equation using solve().
However, the answers given are always values of pi, how do I solve this?
[Result, y] = lorentz(0, 0.725, 15)
function [Result, y] = lorentz(position, CavityLength, BaseRD)
%Enter position, cavity length in m and baserd in microseconds.
c = 299792458; %speed of light in m/s
BaseRD = BaseRD*10^-6;
syms Reflectivity
S = vpasolve(((pi*sqrt(Reflectivity))/(1-Reflectivity))/(c/(2*CavityLength)) == BaseRD, Reflectivity, [0.99 1]);
Result.Reflectivity = S;
Result.Finesse = (pi*sqrt(Result.Reflectivity)/(1-Result.Reflectivity));
Result.FSR = c/(2*CavityLength);
FWHM = Result.FSR./Result.Finesse;
Result.HWHM = FWHM/2;
x = linspace(-1e3,1e3,1e5);
y = (1/pi).*(Result.HWHM./(((x-position).^2)+Result.HWHM.^2));
%y = y.*(height/max(y));
%plot(x,y)
end
Reflectivity: 0.99898752118560808161741982765188
Finesse: 987.1748605317811539461548191278*pi
FSR: 206753419.310345
HWHM: 104719.75511965978378924223514237/pi

5 commentaires

The equation you are solving does not have a solution.
BaseRD = 15;
BaseRD = BaseRD*10^-6;
c = 299792458; %speed of light in m/s
CavityLength = 0.725;
syms x
fun(x) = ((pi*sqrt(x))./(1-x))/(c/(2*CavityLength)) - BaseRD;
%Check the limit
limit(fun, x, Inf)
ans = 
fplot(fun, [0 1e18])
I am getting the solution for Reflectivity that I need, it is about 0.998988.
However, my problem was getting answers as multiples of pi.
I am aware that your problem was with the symbolic notation of pi.
But I was making another point, which I noticed for the given set of data.
Maybe you got that answer for a different set of data, but for the values noted above, there is no solution.
Using this:
c = 299792458;
CavityLength = 0.725;
Pi = sym(pi, 'd');
syms Reflectivity
S = vpasolve(((Pi*sqrt(Reflectivity))/(1-Reflectivity))/(c/(2*CavityLength)) == 14.7E-6, Reflectivity, [0.99 1])
S = 
0.99896686903182896436436014196862
I get the answer I'm looking for.
The BaseRD value is different. And you get your answer.
Also, your comment was marked spam by the Auto Filter, idk how. I have removed the spam notice, and subsequently your flag as well.

Connectez-vous pour commenter.

 Réponse acceptée

Use sym(pi,'d') instead of pi
Or...
use sympref to set floating point output on
Or...
Use vpa
Or...
Use double. For example,
structfun(@double, Result, 'uniform', 0)

Plus de réponses (1)

vpa will turn those products involving pi into more normal looking numbers. For example...
x = 17*sym(pi)
x = 
So x has pi in it.
vpa(x)
ans = 
53.407075111026485053864937515752
vpa yields a symbolic high precision floating point number. But double will also work, and create a double as a result.
double(x)
ans = 53.4071

Produits

Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by