Solve a nonlinear function with one variable

Hi,
I need to solve this function using Matlab in single script:
x - x^2 + 2*{sin(x)*(x-1)} = 0
Would you be able to provide a sample code and method to do this in Matlab?
Thank you very much

回答 (2 件)

KSSV
KSSV 2023 年 1 月 16 日

1 投票

syms x
eq = x - x^2 + 2*sin(x)*(x-1) == 0
eq = 
s = vpasolve(eq)
s = 
0

1 件のコメント

Mohiedin Bagheri
Mohiedin Bagheri 2023 年 1 月 16 日
編集済み: Mohiedin Bagheri 2023 年 1 月 16 日
Thank you @KSSV for your reply.

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

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023 年 1 月 16 日

1 投票

It is quite simple to solve this exercise. Just use vpasolve(), e.g.:
syms x
Solution = vpasolve(x-x^2+2*sin(x)*(x-1)==0)
Solution = 
0
An alternative way is to try Newton-Raphson method

2 件のコメント

Mohiedin Bagheri
Mohiedin Bagheri 2023 年 1 月 16 日
編集済み: Mohiedin Bagheri 2023 年 1 月 16 日
Thank you @Sulaymon Eshkabilov. Assueming that the solution for f1(x)-f2(x)==0 is 'x_sol' (x=0 in this case). then how would be the rest of the code look like if I want to calculate the f1(x_sol)?
Thank you again
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023 年 1 月 16 日
if you are talking about NR method, see this explanation. You'd need to use [for .. end] or [while ... end] loop. See this link where a bunch of matlab codes and discussions of NR method.

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

カテゴリ

質問済み:

2023 年 1 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by