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?

 採用された回答

Birdman
Birdman 2020 年 3 月 24 日

1 投票

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 件のコメント

Bharatha Ravi
Bharatha Ravi 2020 年 3 月 24 日
Thank you!
If suppose i needed to give various vaues of w, How could i give it? Like in a matrix form
Birdman
Birdman 2020 年 3 月 24 日
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 2020 年 3 月 24 日
oh ok! Thank you so much!!
Bharatha Ravi
Bharatha Ravi 2020 年 3 月 24 日
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);
Birdman
Birdman 2020 年 3 月 24 日
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 2020 年 3 月 24 日
The error isn't appearing anymore. But i am not getting any output.
Birdman
Birdman 2020 年 3 月 24 日
Type
sol
at the command line and you will see the results.
Bharatha Ravi
Bharatha Ravi 2020 年 3 月 24 日
Thanks a ton birdman!!!
Bharatha Ravi
Bharatha Ravi 2020 年 3 月 24 日
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?
Birdman
Birdman 2020 年 3 月 24 日
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 2020 年 3 月 24 日
Awesome!! Thank you tons again!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by