Calculating roots of an equation in Matlab.

6 ビュー (過去 30 日間)
Charles
Charles 2022 年 8 月 15 日
編集済み: Dyuman Joshi 2022 年 8 月 16 日
I am trying to calculate switching points. To do this I need to calculate the root of this equation (theta). To do this I have tried the code below.
a = 2
kepa = 3/13
lambda = 9
b = -log(kepa)/lambda
syms theta a
g = 2*(normcdf(a) + (theta - 1) .* normcdf(a*(1-theta)) + 1/(a*sqrt(2*pi)) * (exp(-(a.^2)/2) - ...
exp(-((a.*(1-theta)).^2)/2))) - theta == b;
soltheta = solve(g, theta)
This outputs:
soltheta =
Empty sym: 0-by-1.
I am not sure why this is the case? I know a solution exists and is around 0.175. How do I get this to output a solution for theta? Any help will be greatly appreciated, thank you.

採用された回答

Dyuman Joshi
Dyuman Joshi 2022 年 8 月 15 日
編集済み: Dyuman Joshi 2022 年 8 月 16 日
Some slight tweaks
I used vpasolve cause symbolic solver will give an error and will return the answer using vpasolve only.
Defining a variable and then declaring it as a syms variable will overwrite it's value.
a = 2;
kepa = 3/13;
lambda = 9;
b = -log(kepa)/lambda;
syms theta
g = 2*(normcdf(a) + (theta - 1) .* normcdf(a*(1-theta)) + 1/(a*sqrt(2*pi)) * (exp(-(a.^2)/2) - ...
exp(-((a.*(1-theta)).^2)/2))) - theta == b;
soltheta = vpasolve(g, theta)
soltheta = 
0.17508061864338710498913163970348
Edit - Note that there are 2 solutions to the equation and only the first solution is obtained here (closer to 0).
  1 件のコメント
Charles
Charles 2022 年 8 月 15 日
Thank you!!!

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

その他の回答 (2 件)

Star Strider
Star Strider 2022 年 8 月 15 日
When you delcared ‘a’ as symbolic, you cleared its numeric value.
Try this —
a = 2
a = 2
kepa = 3/13
kepa = 0.2308
lambda = 9
lambda = 9
b = -log(kepa)/lambda
b = 0.1629
syms theta
g = 2*(normcdf(a) + (theta - 1) .* normcdf(a*(1-theta)) + 1/(a*sqrt(2*pi)) * (exp(-(a.^2)/2) - ...
exp(-((a.*(1-theta)).^2)/2))) - theta;
soltheta(1,:) = vpasolve(g == b, -1);
soltheta(2,:) = vpasolve(g == b, 2)
soltheta = 
format long
numtheta = double(soltheta)
numtheta = 2×1
0.175080618643387 1.824919381356613
figure
fplot(g, [-1 3])
yline(b)
grid
.

Torsten
Torsten 2022 年 8 月 15 日
Change
syms theta a
to
syms theta

カテゴリ

Help Center および File ExchangeFormula Manipulation and Simplification についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by