How can I fix this? am trying to find the value of p with bisection method
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commento
Jan
il 30 Ott 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.
Risposte (1)
Shubham Dhanda
il 21 Giu 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 Commenti
Vedere anche
Categorie
Scopri di più su Symbolic Math Toolbox in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!