フィルターのクリア

It takes too long to run the program and in the end I get an error, could you tell me what the error is?

2 ビュー (過去 30 日間)
function f=funcionrr(x)
xini=[0 4*pi];
t=[0 2*pi];
options=odeset('RelTol',1e-13,'AbsTol',1e-13);
[ts,xs]=ode45(@campo_pendulo,t,xini,options);
f=xs(end,1);
end
function px = campo_pendulo(t,x)
px(1)= x(2);
px(2)=sin(x(1))+0.5*sin(t);
px=px';
% Definir los límites de la búsqueda
x_min = 0;
x_max = 2*pi;
x = (x_min + x_max)/2;
while abs(px) > 1e-6
if px > 0
x_max = x;
else
x_min = x;
end
x = (x_min + x_max)/2;
end
end

回答 (1 件)

Torsten
Torsten 2023 年 12 月 1 日
編集済み: Torsten 2023 年 12 月 1 日
You can't change the input for x in function "campo_pendulo".
So you can delete this part of your code because it doesn't influence the results:
% Definir los límites de la búsqueda
x_min = 0;
x_max = 2*pi;
x = (x_min + x_max)/2;
while abs(px) > 1e-6
if px > 0
x_max = x;
else
x_min = x;
end
x = (x_min + x_max)/2;
end
Further it doesn't make sense to use a while loop here because px is not changed within the loop. So once abs(px) > 1e-6, you will enter the loop, but never exit.
f = funcionrr()
f = 82.5899
function f=funcionrr()
xini=[0 4*pi];
t=[0 2*pi];
options=odeset('RelTol',1e-13,'AbsTol',1e-13);
[ts,xs]=ode45(@campo_pendulo,t,xini,options);
f=xs(end,1);
plot(ts,xs)
end
function px = campo_pendulo(t,x)
px(1)= x(2);
px(2)=sin(x(1))+0.5*sin(t);
px=px';
end
  2 件のコメント
Freddy
Freddy 2023 年 12 月 1 日
The work I have to do is that according to that function I must add the dichotomous search, that's why I used the while loop, or how could I propose it?
Torsten
Torsten 2023 年 12 月 1 日
I don't understand what you want to achieve in this part of your code:
% Definir los límites de la búsqueda
x_min = 0;
x_max = 2*pi;
x = (x_min + x_max)/2;
while abs(px) > 1e-6
if px > 0
x_max = x;
else
x_min = x;
end
x = (x_min + x_max)/2;
end

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by