How can I fix this? am trying to find the value of p with bisection method
1 view (last 30 days)
Show older comments
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 Comment
Jan
on 30 Oct 2022
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.
Answers (1)
Shubham Dhanda
on 21 Jun 2023
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 Comments
See Also
Categories
Find more on Symbolic Math Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!