How can I fix this? am trying to find the value of p with bisection method
2 ビュー (過去 30 日間)
古いコメントを表示
syms p
x = 13.61015;
y = 13257;
a = 5.14;
b = 11.47;
c = 0;
f = (x^3 + p^2*x^2 - 10)*sin(x) == 0;
%eqn = y - (x^3 + p^2*x^2 - 10)*sin(x) == 0;
%p = vpasolve(eqn,p);
%p = p(p>a & p<b);
i=0;
while (x^3 + a^2*x^2 - 10)*sin(x) * (x^3 + b^2*x^2 - 10)*sin(x) > 0 && i<5 ;
b = (a+b)/2;
i=i+1;
end
disp (b);
1 件のコメント
Jan
2022 年 10 月 30 日
If you ask for a fixing, it is useful to mention, which problem you have. It is easier to solve a problem than to guess, what the problem is.
The bisection method is a numerical approximation. Why do you choose a symbolic variable? You define f, but do not use it anywhere.
Search in the net for "bisection method". Look in Matlab's FileExchange. Your code has only some few similarities with it.
回答 (1 件)
Shubham Dhanda
2023 年 6 月 21 日
Hi,
I understand that you want to find the root of the equation f using bisection method.
To fix the code, define the value of p initially and then inside the while loop, calculate the value of p using the bisection method.
Below is the MATLAB code implementation of the problem:
syms p
x = 13.61015;
y = 13257;
a = 5.14;
b = 11.47;
c = 0;
i = 0;
p = (a + b)/2;
while abs(x^3 + p^2*x^2 - 10)*sin(x) > c && i < 5
if (x^3 + a^2*x^2 - 10)*sin(x) * (x^3 + p^2*x^2 - 10)*sin(x) > 0
a = p;
else
b = p;
end
p = (a + b)/2;
i = i + 1;
end
disp(p);
Attaching some links for your reference, these might help:
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Symbolic Math Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!