Help in writing a function

조회 수: 1 (최근 30일)
Paul Rogers
Paul Rogers 2020년 10월 31일
댓글: Star Strider 2020년 11월 4일
Hi everyone, I need to write a function to solve this system:
Until now all I can came up with was:
function dz = control1(v,z,parameters)
% gammaT=parameters(1);
phi_0=parameters(2);
psi_0=parameters(3);
psi_c0=parameters(4);
B=parameters(5);
Lc=parameters(6);
W=parameters(7);
H=parameters(8);
C = 0;
gammaT_max = 0.9;
gammaT_min = 0.61;
A = (gammaT_max - gammaT_min)/2; %amplitude
b = gammaT_max - ((gammaT_max - gammaT_min)/2);
hertz = 50;
w=hertz*2*pi;
gammaT = @(t) A*sin(w*t)+b
dz = zeros(2,1);
dz(1)=(1/(4*B*B*Lc))*(z(2)-gammaT(v)*(z(1))^0.5);
psi_c=psi_c0+H*(1+1.5*(z(2)/W-1)-0.5*(z(2)/W-1).^3);
dz(2) =(1/Lc)*(psi_c-z(1));
end
which is obviously wrong since gammaT = @(t) A*sin(w*t)+b shoouldn't be define this way.
I think gammaT should be written in that way but the time in the argument of the sin should be rearranged in some way I don't know

채택된 답변

Star Strider
Star Strider 2020년 10월 31일
which is obviously wrong since gammaT = @(t) A*sin(w*t)+b shoouldn't be define this way.
Why? It appears to be coded correctly with respect to the posted image. It’s being evaluated with respect to your independent variable ‘v’, that appears to be correct. If it should actually be a different variable (such as time), it would be necessary to define the time in the context of the existing variables. We would need more information in order to help you with that.
For what it’s worth, the function runs without error for me using:
parameters = rand(8,1);
and:
[V,Z] = ode45(@(v,z)control1(v,z,parameters), [0 10], rand(2,1));
figure
plot(V, Z)
grid
.
  댓글 수: 30
Paul Rogers
Paul Rogers 2020년 11월 3일
here is the solution I was looking for, so I can observe up tp 50Hz:
init=[0 0]';
options= odeset('MaxStep',0.001); %maximum time-step size
[t,y]=ode45(@greitzer_Jerzak,[0,20],init,options);
This solution allows me to chose the maximum step size of the time, evven if ode45 will still pick up its own points, but at least I make sure they are at a sample frequeny much higher so I can catch the frequencies I need.
thank you everybody, expecially to Star Strider who really put a lot of efford to point me in the right direction.
Star Strider
Star Strider 2020년 11월 4일
As always, my pleasure!
(I can Comment again!)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by