How can I speed up vpasolve?

조회 수: 50 (최근 30일)
Finn Allison
Finn Allison 2021년 8월 12일
댓글: Finn Allison 2021년 8월 12일
I have the following equation that has no analytical inverse
,
where are constants. However, I would like to be able to find for a given z.
I am able to do this with the following code,
syms z thetaz
a = 1;
b = 2;
theta0 = 0;
eqn = (a*sin(theta0)-b*sin(thetaz))./(a*cos(theta0)+b*cos(thetaz)) == z;
v = 0.12; % given value of z
S = vpasolve(eqn,z == v);
vv = S.thetaz %associated value of thetaz
vv = 
but I have thousands of values of v so this takes a very long time.
I have tried using a matlabFunction to speed this up but I'm not sure how to input a z value to give a thetaz value back.
syms z thetaz
a = 1;
b = 2;
theta0 = 0;
z = (a*sin(theta0)-b*sin(thetaz))./(a*cos(theta0)+b*cos(thetaz));
f1 = matlabFunction(z);
check = f1(0.12)
check = -0.0802
The above code thinks I would like to find z from thetaz, is there a way to find thetaz from z using a matlabFunction?
Alternatively is there a way to speed up vpasolve?
Many thanks.

채택된 답변

John D'Errico
John D'Errico 2021년 8월 12일
편집: John D'Errico 2021년 8월 12일
Seriously, it has no solution? Gosh, am I surprised. So what does this do?
syms z thetaz
a = 1;
b = 2;
theta0 = 0;
eqn = (a*sin(theta0)-b*sin(thetaz))./(a*cos(theta0)+b*cos(thetaz)) == z;
thsol = solve(eqn,thetaz,'returnconditions',true)
thsol = struct with fields:
thetaz: [3×1 sym] parameters: [1×1 sym] conditions: [3×1 sym]
thsol.thetaz
ans = 
thsol.parameters
ans = 
k
thsol.conditions
ans = 
So there are infinitely many solutions. Each a multiple of 2*pi away from each other. We can arbitrarily choose the primary solutions, thus with k==0.
syms k
thsol = subs(thsol.thetaz,k,0)
thsol = 
Still not very interesting, but now if we do this:
thsol = matlabFunction(thsol);
thsol(0.12)
ans =
3.0818 - 0.0000i -0.1790 - 0.0000i 3.1416 + 0.6931i
now we find three trivially easy to obtain solutions, two of them are real, one is complex.
But I guess no analytical solution exists, because you said so. :)
  댓글 수: 1
Finn Allison
Finn Allison 2021년 8월 12일
Yes I should have thought of that! Thank you for your explanation and speedy reply.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Conversion Between Symbolic and Numeric에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by