Solving for angle (Beta) using vpasolve

Hello I'm trying to see why I'm not getting the correct angle when i Solve for the following equation. I'm not sure if this is due to a coding error that I dont see or if has to do with an angle property like the refence angle.
The equation I'm solving for is the following the resul i get is
beta =
-196.3722
However if im not mistaken the answer i should get is 23.13 deg.
M1 = 3;
P1 = 1;
theta2 = 5;
thetha3 = 20;
gamma = 1.4;
syms beta
tantheta = tand(theta2);
x = 2*cotd(beta)*((M1^2*((sind(beta))^2)-1));
y = M1^2*(gamma+cosd(2*beta))+2;
eqn = x/y;
result = vpasolve(eqn == tantheta,beta);
beta = result

 Respuesta aceptada

That’s the result I get when I solve it (and then correct it by ) —
M1 = 3;
P1 = 1;
theta2 = 5;
thetha3 = 20;
gamma = 1.4;
syms beta
tantheta = tand(theta2);
x = 2*cotd(beta)*((M1^2*((sind(beta))^2)-1));
y = M1^2*(gamma+cosd(2*beta))+2;
eqn = x/y;
result = solve(tantheta == eqn, beta);
beta = vpa(result) + 180
beta = 
23.133257450785606135761291258498
.

5 comentarios

Benneth Perez
Benneth Perez el 24 de Oct. de 2021
Thanks, I'm not sure why but doing
result = vpasolve(tantheta == eqn, beta);
instead of result = solve(tantheta == eqn, beta);
was giving me a different answer.
As always, my pleasure!
The reason is that solve and vpasolve are different functions, and work differently.
The solve function solves the equation symbolically, and then the vpa call returns a numeric equivalent (although off from the desired result by 180°).
The vpasolve function is a numeric solver, and apparently does not solve symbolically first and then createes a numeric representation of that solution. There may be several different results, and since the function is not a poplynomial, only solves for one of them. Giving it different initial estimates for β may result in different results. See the Tips section for a discussion.
There are actually six solutions, so a different starting point would be necessary for each of them in order to return all of them with vpasolve
M1 = 3;
P1 = 1;
theta2 = 5;
thetha3 = 20;
gamma = 1.4;
syms beta
tantheta = tand(theta2);
x = 2*cotd(beta)*((M1^2*((sind(beta))^2)-1));
y = M1^2*(gamma+cosd(2*beta))+2;
eqn = x/y - tantheta;
figure
hp = fplot(eqn, [0 359]);
grid
xv = hp.XData;
yv = hp.YData;
idx = find(diff(sign(yv)));
idx = idx([1:3 5:7]);
xv(idx);
for k = 1:numel(idx)
idxrng = (-1:1)+idx(k);
xexact(k) = interp1(yv(idxrng), xv(idxrng), 0);
end
xexact
xexact = 1×6
23.3458 88.1438 163.5677 203.2841 268.1513 343.5227
hold on
plot(xexact, zeros(size(xexact)), '+r')
hold off
I did this numerically because that is simply more efficient than making numerical guesses.
So vpasolve returned a ‘correct’ solution, simply not the desired solution!
.
Benneth Perez
Benneth Perez el 24 de Oct. de 2021
Wow, thanks i figured i was off by 180 which in most cases worked but this starting points it was not working.
After noticing the code worked by just switching to solve i tried an input of theta2 = 15 and i started getting an odd answer again. Follow up I couldnt figure out what the issue was. I tried this new approach you have and it seems to work just fine. Although im wondering why my approach returns some weird solution.
I think part of it has to do with understanding the tangent plot and part of it with figuring out how to use vpasolve and solve. I appreciate your help! if you could take a quick look at my link that be great.
Walter Roberson
Walter Roberson el 24 de Oct. de 2021
vpasolve() uses a modified Newton-Raphson algorithm. It might need to take the derivative of the function internally first.
Star Strider
Star Strider el 24 de Oct. de 2021
As always, my pleasure!
I looked at the linked Question, and posted an Answer (of sorts) to it, although I could not find a symbolic solution for it.
.

Iniciar sesión para comentar.

Más respuestas (0)

Productos

Versión

R2021b

Preguntada:

el 24 de Oct. de 2021

Comentada:

el 24 de Oct. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by