Solve issue in Matlab R2018b

I was using Matlab R2014a earlier where I was able to solve this equation easily, but in Matlab R2018b it is returning the
error in sol = solve(eqn,a,[0 pi]); I couldn't figure out why. The working code in Matlab 2014a is
syms a T
v2=-2.3750
g=1;
b=0;
e2=0.5;
k=2.5;
w=-2*cos(k);
eqn = sin(3*k+a)./sin(2*k+a)==v2-w+(g.*T.^2)+(e2.*T.^2.*sin(k)^2)./(sin(2*k+a)^2+b*T.^2*sin(k).^2);
sol = solve(eqn,a,[0 pi]);
digits(5)
solutions = vpa(subs(sol),3)
Please note that "a" is to be bound to take values between 0 and pi.

3 个评论

What is the exact error (ALL the red text)? Have you tried it with R2019a?
Only you can specify the range in vpasolve() where only one parameter is not known but with solve you can't specify the bounds.
@Image Analyst:
The exact errors are as follows (all the red text)
Error in solve>getEqns (line 429)
[eqns, vars] = sym.getEqnsVars(argv{:});
Error in solve (line 226)
[eqns,vars,options] = getEqns(varargin{:});
Error in SolutionsPlot (line 11)
sol = solve(eqn,a,[0 pi]);

请先登录,再进行评论。

 采纳的回答

Restrict ‘a’ using an assume call.
Try this:
syms a T
assume(a >= 0 & a <= pi)
v2=-2.3750
g=1;
b=0;
e2=0.5;
k=2.5;
w=-2*cos(k);
eqn = sin(3*k+a)./sin(2*k+a)==v2-w+(g.*T.^2)+(e2.*T.^2.*sin(k)^2)./(sin(2*k+a)^2+b*T.^2*sin(k).^2);
[sol,prms,conds] = solve(eqn,a, 'ReturnConditions',true)
digits(5)
solutions = vpa(subs(sol),3)
vpaconds = vpa(conds)

4 个评论

@Star Strider Thanks. Is there a way that I can get those nice numeric solutions which I used to get with the same code in R2014a? These conditions make it hard to explicityly see the numerical solutions.
My pleasure.
The ‘conds’ result is likely as good as it gets. Note that it is a function of ‘T’, and with the inequality conditions stated in the vector, neither coeffs or any related function (such as numden or sym2poly) will produce a purely numeric result.
Adding:
Tsol(:,1) = solve(conds(1), T)
Tsol(:,2) = solve(conds(2), T)
doesn’t completely resolve the problem, since the result is now a funciton of ‘x’:
Tsol =
-2*exp(-5i/4)*(-((exp(x*2i)*exp(10i) - 1)*(4478027322974943*exp(5i/2) - 1125899906842624*exp(x*2i)*exp(15i) - 4478027322974943*exp(x*2i)*exp(25i/2) + 1125899906842624))/(4503599627370496 + 4503599627370496*exp(x*4i)*exp(20i) - 12233297969360201*exp(x*2i)*exp(10i)))^(1/2)
2*exp(-5i/4)*(-((exp(x*2i)*exp(10i) - 1)*(4478027322974943*exp(5i/2) - 1125899906842624*exp(x*2i)*exp(15i) - 4478027322974943*exp(x*2i)*exp(25i/2) + 1125899906842624))/(4503599627370496 + 4503599627370496*exp(x*4i)*exp(20i) - 12233297969360201*exp(x*2i)*exp(10i)))^(1/2)
The only other option I can provide is:
Tfcn = matlabFunction(Tsol)
that will produce an anonymous function to evaluate those.
@Star Strider, Many thanks for your elaboration.
As always, my pleasure.

请先登录,再进行评论。

更多回答(0 个)

类别

产品

版本

R2018b

标签

Community Treasure Hunt

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

Start Hunting!

Translated by