How can I fix this? am trying to find the value of p with bisection method

3 次查看(过去 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
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
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);
11.3711
Attaching some links for your reference, these might help:

类别

Help CenterFile Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by