From Scientific Calculator [Solve] to matlab

4 ビュー (過去 30 日間)
Alex
Alex 2017 年 10 月 24 日
コメント済み: Torsten 2017 年 10 月 24 日
Hi all, with my scientific calculator I could try something as the following
SHIFT+CLR(9) >> (3)>>Reset All >>[=] Reset All >> Press [AC]
-Set the calculator on the right limits:
sin(30)=1/2
sin(x) = 1/2 and solve for x [SHIFT] [SOLVE] [=] = 30
or
cos(X)^2*cos(3X)^2 = 0.5 and then SHIFT>>SOLVE
How I can implement something like that in matlab (especially for the second function at the bottom? How I can implement this solve functionality in matlab? I would like to thank you in advance for your help

回答 (4 件)

Mischa Kim
Mischa Kim 2017 年 10 月 24 日
編集済み: Mischa Kim 2017 年 10 月 24 日
Alex, use something like
fun = @(X) cos(X)^2*cos(3*X)^2 - 0.5;
options = optimoptions('fsolve','Display','none','PlotFcn',@optimplotfirstorderopt);
sol = fsolve(fun,0,options)
The options command is not required but shows you some of the capabilities of MATLAB.

Torsten
Torsten 2017 年 10 月 24 日
syms x
eqn = cos(x)^2*cos(3*x)^2-0.5 == 0;
sol = solve(eqn)
or
syms x
eqn = cos(x)^2*cos(3*x)^2-0.5 == 0;
sol = vpasolve(eqn)
Best wishes
Torsten.

Alex
Alex 2017 年 10 月 24 日
Thanks a lot for all the replies. Unfortunately both suggestions
syms x
eqn = cos(x)*cos(3*x)-0.5707 == 0;
sol = vpasolve(eqn)
fun = @(X) cos(X)*cos(3*X) - 0.5707;
options = optimoptions('fsolve','Display','none','PlotFcn',@optimplotfirstorderopt);
sol = fsolve(fun,0)
do not return any solution, even though I simplified the equation. At the same time the calculator is spot on. What is the extra level of details that are required from matlab in this regard?
Thanks a lot Alex
  1 件のコメント
Torsten
Torsten 2017 年 10 月 24 日
Maybe you neither have the symbolic toolbox nor the optimization toolbox installed ?
Does
x0 = 0;
fun = @(X) cos(X)*cos(3*X) - 0.5707;
sol = fzero(fun,x0)
work ?
Best wishes
Torsten.

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


Steven Lord
Steven Lord 2017 年 10 月 24 日
Since this is one equation in one unknown, you can use fzero to solve this.
>> f = @(x) cos(x)*cos(3*x)-0.5707;
>> result = fzero(f, 0);
>> check = f(result)
check =
0
However, it appears your calculator computes the cosine of angles in degrees. The cos function in MATLAB computes the cosine of an angle in radians. To compute the cosine of an angle in degrees in MATLAB, use the cosd function instead of cos.

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by