Thread Subject: Problem with using ODE solvers

Subject: Problem with using ODE solvers

From: Markthomas

Date: 7 Nov, 2009 19:10:04

Message: 1 of 2

I am trying to run an ODE case usin ode45... the scripts are seen below:
---------------------------------------------code 1------------------------------------------------------------------
function varargout = odefile_V2(t,T,flag,tau,ET,R1,rho1,L1,C1,R3,R2,rho2,L2,C2,rho3,L3,C3)

switch flag
    case ''
        varargout{1} = f(t,T,tau,ET,R1,rho1,L1,C1,R3,R2,rho2,L2,C2,rho3,L3,C3);
    case 'init'
        [varargout{1:3}] = init(tau,ET,R1,rho1,L1,C1,R3,R2,rho2,L2,C2,rho3,L3,C3);
end

%--------------------------------------------------------------------------
function dydt = f(t,T,tau,ET,R1,rho1,L1,C1,R3,R2,rho2,L2,C2,rho3,L3,C3)

dydt(1) = (-(ET*(T(1)^4-(1200*(1-exp(-t/tau)))^4)+(R1*ET*(T(1)^4-(1200*(1-exp(-t/tau)))^4)+T(1)-T2(t))/R2)/rho1/L1/C1+4*ET*R1*(1200*(1-exp(-t/tau)))^3*((1200/tau)*exp(-t/tau)))/(4*ET*R1*T(1)^3+1);
dydt(2) = (R3*ET*R1*T(1)^4+R3*T(1)+(-R3-R2)*T(2)-R3*ET*R1*(1200*(1-exp(-t/tau)))^4+R2*T(3))/R2/R3/rho2/L2/C2;
dydt(3) = (T(2)-T(3))/R3/rho3/L3/C3;

function [tspan,y0,options] = init(tau,ET,R1,rho1,L1,C1,R3,R2,rho2,L2,C2,rho3,L3,C3)
tspan = [0; 100];
y0 = [300; 300; 300];
options = [];
---------------------------------------------code 2------------------------------------------------------------------
clear; clc; close all
% Material @ Node 0
T0_0 = 300;
% Material @ Node 1
T1_0 = 300;
K1 = 60;
rho1 = 8000;
C1 = 440;
L1 = .07;
% Material @ Node 2
T2_0 = 300;
K2 = 1.4;
rho2 = 1300;
C2 = 1500;
L2 = .04;
% Material @ Node 2
T3_0 = 300;
K3 = 50;
rho3 = 7500;
C3 = 400;
L3 = .02;
%Resistances
R1 = L1/(2*K1);
R2 = R1 + (L2/(2*K2));
R3 = (L2/(2*K2)) + (L3/(2*K3));
% Other Constants
ET = 4e-8;
tau = 50;

[t,T]=ode45('odefile_V2',tau,ET,R1,rho1,L1,C1,R3,R2,rho2,L2,C2,rho3,L3,C3);
------------------------------------------------------------------------------------------------------------------------
i keep getting errors and was hoping somebody was able to figure out what is going wrong. I have rewritten the code several times and can't seem to get it to work... any help would be great!

Thanks!
MT

Subject: Problem with using ODE solvers

From: Chris

Date: 14 Nov, 2009 23:40:20

Message: 2 of 2

If I understand this code correctly, then I believe you might have a similar problem since it seems like the ode45 function needs the following arguments.

ode45(function, time span, initial conditions)

However, with your ode45 function:
[t,T]=ode45('odefile_V2',tau,ET,R1,rho1,L1,C1,R3,R2,rho2,L2,C2,rho3,L3,C3);

tau is probably suppose to be the time span, which I think is suppose to be a function.

But, I am still learning the MATLAB, so a lot of your other code still looks too advanced for me.

"Markthomas " <cutonem@clarkson.edu> wrote in message <hd4gmc$amd$1@fred.mathworks.com>...
> I am trying to run an ODE case usin ode45... the scripts are seen below:
> ---------------------------------------------code 1------------------------------------------------------------------
> function varargout = odefile_V2(t,T,flag,tau,ET,R1,rho1,L1,C1,R3,R2,rho2,L2,C2,rho3,L3,C3)
>
> switch flag
> case ''
> varargout{1} = f(t,T,tau,ET,R1,rho1,L1,C1,R3,R2,rho2,L2,C2,rho3,L3,C3);
> case 'init'
> [varargout{1:3}] = init(tau,ET,R1,rho1,L1,C1,R3,R2,rho2,L2,C2,rho3,L3,C3);
> end
>
> %--------------------------------------------------------------------------
> function dydt = f(t,T,tau,ET,R1,rho1,L1,C1,R3,R2,rho2,L2,C2,rho3,L3,C3)
>
> dydt(1) = (-(ET*(T(1)^4-(1200*(1-exp(-t/tau)))^4)+(R1*ET*(T(1)^4-(1200*(1-exp(-t/tau)))^4)+T(1)-T2(t))/R2)/rho1/L1/C1+4*ET*R1*(1200*(1-exp(-t/tau)))^3*((1200/tau)*exp(-t/tau)))/(4*ET*R1*T(1)^3+1);
> dydt(2) = (R3*ET*R1*T(1)^4+R3*T(1)+(-R3-R2)*T(2)-R3*ET*R1*(1200*(1-exp(-t/tau)))^4+R2*T(3))/R2/R3/rho2/L2/C2;
> dydt(3) = (T(2)-T(3))/R3/rho3/L3/C3;
>
> function [tspan,y0,options] = init(tau,ET,R1,rho1,L1,C1,R3,R2,rho2,L2,C2,rho3,L3,C3)
> tspan = [0; 100];
> y0 = [300; 300; 300];
> options = [];
> ---------------------------------------------code 2------------------------------------------------------------------
> clear; clc; close all
> % Material @ Node 0
> T0_0 = 300;
> % Material @ Node 1
> T1_0 = 300;
> K1 = 60;
> rho1 = 8000;
> C1 = 440;
> L1 = .07;
> % Material @ Node 2
> T2_0 = 300;
> K2 = 1.4;
> rho2 = 1300;
> C2 = 1500;
> L2 = .04;
> % Material @ Node 2
> T3_0 = 300;
> K3 = 50;
> rho3 = 7500;
> C3 = 400;
> L3 = .02;
> %Resistances
> R1 = L1/(2*K1);
> R2 = R1 + (L2/(2*K2));
> R3 = (L2/(2*K2)) + (L3/(2*K3));
> % Other Constants
> ET = 4e-8;
> tau = 50;
>
> [t,T]=ode45('odefile_V2',tau,ET,R1,rho1,L1,C1,R3,R2,rho2,L2,C2,rho3,L3,C3);
> ------------------------------------------------------------------------------------------------------------------------
> i keep getting errors and was hoping somebody was able to figure out what is going wrong. I have rewritten the code several times and can't seem to get it to work... any help would be great!
>
> Thanks!
> MT

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
ode45 Markthomas 7 Nov, 2009 14:14:02
errors Markthomas 7 Nov, 2009 14:14:02
help Markthomas 7 Nov, 2009 14:14:02
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com