How can I speed up vpasolve?
조회 수: 50 (최근 30일)
이전 댓글 표시
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
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)
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.
댓글 수: 0
채택된 답변
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.thetaz
thsol.parameters
thsol.conditions
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)
Still not very interesting, but now if we do this:
thsol = matlabFunction(thsol);
thsol(0.12)
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. :)
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!