Ho do i convert this number to an integer?

I'm using this code to solve an equation.
syms b
w=1150;di=32.59;do=23.44;
sol=solve((w-(2.*90.*sind(b))).^2==(w-(90.*sind(b+di))-(90.*sind(b-do))).^2+((90.*cosd(b-do))-(90.*cosd(b+di))).^2,b);
vpa(sol)
I'm solving for b and im supposed to get around 28.1606 but im getting
ans =
144.93095960237559740993061817135 + 177.92191183196224178797359740301i
Why am i not gettin gthe answer? Do i have to onvert it?

 Réponse acceptée

Birdman
Birdman le 24 Mar 2020
Try vpasolve:
w=1150;di=32.59;do=23.44;
sol=vpasolve((w-(2.*90.*sind(b))).^2==(w-(90.*sind(b+di))-(90.*sind(b-do))).^2+((90.*cosd(b-do))-(90.*cosd(b+di))).^2,b)
vpasolve solves the equation numerically.

11 commentaires

Bharatha Ravi
Bharatha Ravi le 24 Mar 2020
Thank you!
If suppose i needed to give various vaues of w, How could i give it? Like in a matrix form
Simple for loop should help. Consider the following example:
w=[1150;1250;1350];di=32.59;do=23.44;
for i=1:numel(w)
sol(i)=vpasolve((w(i)-(2.*90.*sind(b))).^2==(w(i)-(90.*sind(b+di))-(90.*sind(b-do))).^2+((90.*cosd(b-do))-(90.*cosd(b+di))).^2,b);
end
Bharatha Ravi
Bharatha Ravi le 24 Mar 2020
oh ok! Thank you so much!!
Bharatha Ravi
Bharatha Ravi le 24 Mar 2020
im getting this error:
Undefined function or variable 'b'.
Error in trial (line 9)
sol(i)=vpasolve((w(i)-(2.*90.*sind(b))).^2==(w(i)-(90.*sind(b+di))-(90.*sind(b-do))).^2+((90.*cosd(b-do))-(90.*cosd(b+di))).^2,b);
I forgot to define b:
syms b
w=[1150;1250;1350];di=32.59;do=23.44;
for i=1:numel(w)
sol(i)=vpasolve((w(i)-(2.*90.*sind(b))).^2==(w(i)-(90.*sind(b+di))-(90.*sind(b-do))).^2+((90.*cosd(b-do))-(90.*cosd(b+di))).^2,b);
end
Bharatha Ravi
Bharatha Ravi le 24 Mar 2020
The error isn't appearing anymore. But i am not getting any output.
Type
sol
at the command line and you will see the results.
Bharatha Ravi
Bharatha Ravi le 24 Mar 2020
Thanks a ton birdman!!!
Bharatha Ravi
Bharatha Ravi le 24 Mar 2020
Is there any mistake in this:
syms b
l=1550;R=[2500;2600;2700;2800];w=1150;
for i=1:numel(R)
di(i)=atand(l./(R(i)-(w/2)));do(i)=atand(l./(R(i)+(w/2)));
sol=vpasolve((w-(2.*90.*sind(b))).^2==(w-(90.*sind(b+di(i)))-(90.*sind(b-do(i)))).^2+((90.*cosd(b-do(i)))-(90.*cosd(b+di(i)))).^2,b);
end
sol
i should be getting 4 answers but im getting only 1...which i dont is right or wrong.
what corrections should i make?
Replace the line
sol=vpasolve((w-(2.*90.*sind(b))).^2==(w-(90.*sind(b+di(i)))-(90.*sind(b-do(i)))).^2+((90.*cosd(b-do(i)))-(90.*cosd(b+di(i)))).^2,b);
with
sol(i)=vpasolve((w-(2.*90.*sind(b))).^2==(w-(90.*sind(b+di(i)))-(90.*sind(b-do(i)))).^2+((90.*cosd(b-do(i)))-(90.*cosd(b+di(i)))).^2,b);
Bharatha Ravi
Bharatha Ravi le 24 Mar 2020
Awesome!! Thank you tons again!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Mathematics dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by