필터 지우기
필터 지우기

ode45 not enough input argument

조회 수: 1 (최근 30일)
saramatlab
saramatlab 2014년 9월 8일
편집: saramatlab 2014년 9월 9일
Hi everyone, i have a problem with an ode function, i show you the code:
%Ode function:
function dTdt=ode1(t,T,d,e)
dTdt=d-e*T
return
%main code
T0=293;
T1=400;
Tf2=293;
a=0.2;
tchange=(T1-T0)/a;
for t=1:(tchange)+1
Tf(t)=T0+a*(t-1);
d=(Tf(t)-Tf2)/(R*C)
e=-2/(R*C)
[t,T] = ode45(ode1,[0 336],293,d,e)
end
Matlab says to me:
Error using ode1 (line 2) Not enough input arguments.
Error in Untitled (line 27) [t,T] = ode45(ode1,[0 336],293,d,e)
i know that i have to put some value for d and e, but how can i do if they change every step because they are in a for cycle? What else is wrong? Please please help me, i can't do anything by myself!

채택된 답변

Mischa Kim
Mischa Kim 2014년 9월 8일
saramatlab, use
function my_ode()
%main code
T0 = 293;
T1 = 300;
Tf2 = 293;
a = 0.2;
R = 1; % not defined in your code
C = 1; % not defined in your code
tchange = (T1-T0)/a;
for ii = 1:(tchange)+1
Tf(ii) = T0 + a*(ii-1);
d = (Tf(ii) - Tf2)/(R*C);
e = -2/(R*C);
% d and e need to be passed as parameters
[t,T] = ode45(@ode1,[0 336],293,[],[d,e]);
end
end
function dTdt = ode1(t,T,param)
d = param(1);
e = param(2);
dTdt = d - e*T;
end
Put both functions in the same function file and name it my_ode.m. The code is in no way optimized, but runs properly.
  댓글 수: 1
saramatlab
saramatlab 2014년 9월 8일
편집: saramatlab 2014년 9월 9일
Thank you so much, it works!!! :):):) Can i ask you another one question? i've to compare my solution with one other,i have to check that at the end my ode function this relationship: a*t+293=400 is true.
t is the same variable that i have in the ode, how can i put in my ode function this relationship so that t is the same for both the equation?

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

추가 답변 (2개)

Andy L
Andy L 2014년 9월 8일
편집: Andy L 2014년 9월 8일
You need to vectorise your inputs to ode1 as below:
%Ode function:
function dTdt = ode1(t,T,d,e)
becomes
function dTdt = ode1(t,Y)
Y(1) = T;
Y(2) = d;
Y(3) = e;
Check example 1 in this link ode45
  댓글 수: 3
Andy L
Andy L 2014년 9월 8일
A few things to consider:
  • When is T declared?
  • When is Y declared?
  • Should T be a vector?
  • How are you storing the results of your optimisations?
saramatlab
saramatlab 2014년 9월 8일
T is the variable that i want to calculate with the differential equation, it's a temperature profile and i only know its initial value. I am not storing the results beacuse i'm not able to :(

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


saramatlab
saramatlab 2014년 9월 9일
Can i ask you another one question? i've to compare my solution with one other,i have to check that at the end my ode function this relationship: a*t+293=400 is true.
t is the same variable that i have in the ode, how can i put in my ode function this relationship so that t is the same for both the equation?

카테고리

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