필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
Nikolas
Nikolas 2022년 10월 30일
답변: Shubham Dhanda 2023년 6월 21일
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