필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Ode45 data keeps refreshing

조회 수: 1 (최근 30일)
Lazaros Christoforidis
Lazaros Christoforidis 2020년 4월 24일
마감: MATLAB Answer Bot 2021년 8월 20일
Hello, I would appreciate if someone help me.
My problem is that I have 5 polyonimals and I made them switch when the value reaches umax it switch to the next one, but I want to stay there or move forwand to the next one polyonimal.
I did the following code, the problem is ode calls this function at each loop and u1max,u2max,u3max,u4max,u5max keeps getting refreshing.
function udot = ok3(t,u,p1,p2,p3,p4,p5,m,maxu,maxT,u1max,u2max,u3max,u4max,u5max)
syms z p(z)
T=symsum(p(m+1-z)*(u(1))^z,z,0,m);
if u(1)<=u1max
for y=1:m+1
T=subs(T,p(y),p1(y));
end
elseif u(1)<=u2max
u1max=5000;
for y=1:m+1
T=subs(T,p(y),p2(y));
end
elseif u(1)<=u3max
u1max=5000; u2max=5000;
for y=1:m+1
T=subs(T,p(y),p3(y));
end
elseif u(1)<=u4max
u1max=5000; u2max=5000; u3max=5000
for y=1:m+1
T=subs(T,p(y),p4(y));
end
elseif u(1)<=u5max
u1max=5000; u2max=5000; u3max=5000; u4max=5000;
for y=1:m+1
T=subs(T,p(y),p5(y));
end
else
T=maxT;
u(1)=maxu;
end
.
.
.
.
udot=double([SM1;SF]);
end

답변 (1개)

darova
darova 2020년 4월 24일
function udot = ok3(t,u,P,m,maxu,maxT,umax)
syms z p(z)
T=symsum(p(m+1-z)*(u(1))^z,z,0,m);
persistent umaxc
if isempty(umaxc)
umaxc = u(1);
end
umaxc = max(u(1),umaxc);
if any(umaxc <= umax)
k = find(umaxc<=umax,1,'first');
pp = P{k};
%code
else
T=maxT;
u(1)=maxu;
end
end
Your main script
clear function % clear persistent variable
P = {p1 p2 p3 p4 p5};
umax = [u1max u2max u3max u4max u5max];

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by