답변 (2개)

Star Strider
Star Strider 2023년 5월 6일
편집: Star Strider 2023년 5월 6일

0 개 추천

The ode45 call needs to be —
[t,y] = ode54(@(t,y)assignment(t,y,u,d), tspan, ic)
where ‘u’ and ‘d’ have previously been defined and are present in the calling function workspace.
EDIT — (6 May 20213 at 17:36)
Your ‘assignment’ function apppears to be intended as an ODE function that would be input to one of the differential equation integrators, such as ode45. If so, my approach here should work.
The ODE integrator function will provide the ‘t’ and ‘y’ variables (initially from the ‘tspan’ and ‘ic’ arguments, respecively). It will then calculate subsequent values to evaluate and integrate the ‘assignment’ function.
To illustrate —
u = @(t) sin(2*pi*t/5); % Create Missing Function
d = @(t) cos(2*pi*t/10); % Create Missing Function
[t,y] = ode45(@(t,y)assignment(t,y,u,d), [0 25], 0); % Integrate 'assignment'
figure
plot(t,y)
grid
xlabel('Time')
ylable('y(t)')
title('‘assignment’ Integrated')
function dydt = assignment(t,y,u,d)
dydt = zeros(1,1);
dydt = (-1/5)*y(1) + (0.35/5)*u(t) + d(t)/5;
end
Make appropriate changes to get the desired result.
.
Image Analyst
Image Analyst 2023년 5월 6일

0 개 추천

You probably jsut clicked the green Run triangle on the tool ribbon without actually assigning anything for t, y, u, and d. Assign those FIRST, then run your function from the command window passing in the variables.
t = whatever
y = whatever
u = whatever
d = whatever
dydt = assignment(t,y,u,d)

댓글 수: 1

Abdulelah AlQahtani
Abdulelah AlQahtani 2023년 5월 6일
That is exactly what I did, but I don't know what is supposed to be in the file and what should be in the command

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

카테고리

질문:

2023년 5월 6일

편집:

2023년 5월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by