How can I speed up vpasolve?

51 ビュー (過去 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 Center および File ExchangeConversion 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