COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

Changing Inputs per Time Step in ODE45

• Email
• Follow

```Hi,

I am a new MATLAB user and I am attempting to use the ODE45 solver to solve a system of 2 1st order differential equations. However, I need to vary the equation inputs, u1 and u2, at every time step.
I have attempted to do this by using a For loop and If statement to assign constant value to the input variables u1 and u2 at each time step selected from two vectors, U1 and U2.
The code executes in MATLAB and generates outputs however the results do not appear to be correct.
If someone could review the code to check that my for and if statements are correct it would be greatly appreciated.
Sarah

function [Store1] = ModelS1(Inputs, T1, b, c)
% Define Store input time series
U1 = Inputs(:,1);
U2 = Inputs(:,2);
% Set the initial conditions
Xo = [b;c];
% Define the time span over which to execute the model
tspan = 0:1:99;
% Implementation of u1 and u2 within the model
n = length (tspan);
for a=1:n;
if(tspan(a))
u1 = U1(a);
u2 = U2(a);
[t,X] = ode45(@Store_1,tspan,Xo,[],u1,u2,T1);
end
end
% Output
Store1 = [t X(:,1) X(:,2)];

% System of Equations
% dx1/dt = (u1 - x1)/T
% dx2/dt = ((u1*u2) - (x1*x2))/(T*x1)
function [dx_dt]= Store_1(t,x,u1,u2,T1)
% System of Differential Equations
dx_dt(1) = (u1 - x(1))/T1;
dx_dt(2) = ((u1*u2) -(x(1)*x(2)))/(T1*x(1));
% Collect  derivatives into a column vector
dx_dt = dx_dt';
return
```
 0

See related articles to this posting

```"Sarah Halliday" <s.j.halliday@student.reading.ac.uk> wrote in message
news:i0krdm\$jro\$1@fred.mathworks.com...
> Hi,
>
> I am a new MATLAB user and I am attempting to use the ODE45 solver to
> solve a system of 2 1st order differential equations. However, I need to
> vary the equation inputs, u1 and u2, at every time step.

So you're trying to solve your system of ODEs multiple times for various
different values of u1 and u2 that you pass in as additional input
arguments?

> I have attempted to do this by using a For loop and If statement to assign
> constant value to the input variables u1 and u2 at each time step selected
> from two vectors, U1 and U2.
> The code executes in MATLAB and generates outputs however the results do
> not appear to be correct.
> If someone could review the code to check that my for and if statements
> are correct it would be greatly appreciated.
> Thank you for your time,
> Sarah
>
> function [Store1] = ModelS1(Inputs, T1, b, c)
> % Define Store input time series U1 = Inputs(:,1);
> U2 = Inputs(:,2);
> % Set the initial conditions Xo = [b;c];
> % Define the time span over which to execute the model tspan = 0:1:99;
> % Implementation of u1 and u2 within the model
> n = length (tspan);

This looks off to me.  You shouldn't care about the length of the tspan
vector here; you should care about how many pairs of u1 and u2 parameters
you have to process.

for whichparams = 1:size(Inputs, 1)
u1 = Inputs(whichparam, 1);
u2 = Inputs(whichparam,  2);
% I would also suggest using an anonymous function
[t, X] = ode45(@(t, y) Store_1(t, y, u1, u2), tspan, Xo);
% Do something with this parameter value's t and X output from ODE45
end

If instead you're using u1 and u2 as time-varying parameters, so your
equations are:

y' = f(t, y(t), u1(t), u2(t))

then you will need to pass ALL of U1 and U2 into your ODE function so you
can interpolate it for time values at which you don't have an actual value.
Use INTERP1 for this.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
http://www.mathworks.com

```
 0
Reply slord (13686) 7/2/2010 2:14:57 PM

```Thanks Steve, treating u1 and u2 as time-varying parameters has sorted out the probelm.
```
 0

```"Sarah Halliday" wrote in message <i17dsu\$h5l\$1@fred.mathworks.com>...
> Thanks Steve, treating u1 and u2 as time-varying parameters has sorted out the probelm.
i have vectors u1 and u2 in hand .
can you please elaborate on the following two issues
1.how to pass u1 and u2 to ode45
2.how to handle u1 and u2 inside the function
```
 0

3 Replies
1344 Views

Similar Articles

12/7/2013 1:14:47 AM
page loaded in 2612 ms. (0)

Similar Artilces:

DAQmx 4 samples per second per channel
I have scxi 1102,with the new DAQmx assistant, my objective is to record analog input voltage on each channel (only five channels 0- 4) 4 samples of data per second per channel. In DAQmx assistant: number of samples = 4, rate: 60hz, and in my while loop I put a delay of 15 msec. Is this correct? is there a simple equation for setting the parameters? Later on if I add one channel for collecting temperature. What do I need to change? (I know this has to be a different DAQmx assistant task, cannot combine with purely the above five analog inputs) and later on if I add another set of 5 analog inputs voltage and one temperature. What do I need to change? Bharat Thank you very much, it helps me a lot. If I place the block diagram of the VI inside a while loop to continously acquire data and write to file. Q1. Do I put a time delay inside the while loop? If yes, msec? Q2. Do I just place the DAQmx Start.Vi and the DAQmx Read.vi inside the while loop? Again, really appreciate your answer.

driver per xp pro
Sto cercando i driver per far funzionare il fax interno su windows xp pro. Qualcuno mi pu� aiutare perfavore?

One Requirement Per Sentence
test can be defined for it.". However, they seem to be silent on the concept that there should only be one requirement per sentence (at least, I haven't seen any such discussion yet). Accordingly, this project's software team is combining a whole collection of requirements into one numbered paragraph, and calling that paragraph one "requirement" that's uniquely numbered in conformance to the DIDs. Can you folks give me a pointer or two to an industry or government standard that specifies one requirement per sentence? I know that this is the industry norm but it'... which allows use of the > MIL-STD-498 DIDs. But, I digress...) > > The DIDs all say stuff like "Each requirement shall be assigned a > project-unique identifier to support testing and traceability and > shall be stated in such a way that an objective test can be defined > for it.". However, they seem to be silent on the concept that there > should only be one requirement per sentence (at least, I haven't seen > any such discussion yet). Uh, that would lead to contortions to stretch and contract sentences. > Accordingly, this project's software

sendmail per-recipient routing
is calculated. If you do a per-user lookup during that rule set then you can re-direct individual users to any other address you wish. (In effect they get relayed.) To use ldap, you simply include the ldap setups with send mail, and then use the ldap lookup syntax to do the lookup (instead of some other lookup syntax). Before you try to do that, check the various pre-canned features. I believe that "userdb" and "genericstable" can be used to set this up, though I didn't use them at the time, so I can't suggest exactly how to use them. I did this by inserting

per-processor synchronization idea
I'm just finishing my work on my memory allocator and I had some further interesting ideas about synchronziation. My allocator is very aggressive in thread-local pooling and there might be circumstances where the sum of all per-thread-pools for small blocks are quite large. So the idea of a per -processor pool crossed my mind. But this includes a problem: The kernel would have to support addtional infor- mation in the thread-local-storage region to indicate processor-local storage. The allocator would have to get this information from the TLS-block (on Win32 /x86 this is done to access.... Compared to what we will do while we will hold that lock, locking will be an expensive operation a least on x86 -systems because a CAS with a lock-prefix relatively slow (on my Athlon about three times slower and I wouldn't wonder if it would be even slower on Intel's P4-CPUs). So if we could prevent any migration of our thread and all other threads operating on that lock could do the same, we could use the CAS without a lock-prefix! This would be quite simple to support for the OS' scheduler by a simple per-thread flag in the TLS-area. Once this flag is set by a thread, this would

Efficient per-class allocator
, it says that the call to test1(1000 * 1000) takes 29 / 70 seconds and the call to test2(1000 * 1000) takes 1 / 70 seconds. I would like to find a per-class allocator that uses linked lists to provide performance that takes as long as the call to test2 takes. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] On Oct 24, 2:02 pm, Davin Pearson <davin.pear...@gmail.com> wrote: > Consider the following g++ code: > > #include "../../2006/nogc2/global.hh" > > class Foo > { >...; } > > Apologies for the lack of standard code in the main function. I am > using the Allegro graphics library and my own string class. The rest > of the code is portable however. When I run the above code, it says > that the call to test1(1000 * 1000) takes 29 / 70 seconds and the call > to test2(1000 * 1000) takes 1 / 70 seconds. I would like to find a > per-class allocator that uses linked lists to provide performance that > takes as long as the call to test2 takes. The answer is going to depend a lot oon the answers to : 1) is create() called by more than one thread

UK JOB,15000\$ PER MONTH
make money every where. work 1 hour in day,& get 15,000\$ per month. No Investment. 100% Guaranteed Income.Proofs & Details On http://onlinejob8home.blogspot.com/

Number of chars per line ?
Does anyone know the number of chars per line in AIX? Example, I want to capture all output of the command " ps auxeww 7 <PID> ", but I can see that it cuts off somewhere around 2048 chars? Is there somewhere I can set this value to be greater? Or is this a limitation of AIX (5300-03). Do you another method I could use to capture entire output line? Thanks in advance. Cheers shpot4@yahoo.com wrote: > Does anyone know the number of chars per line in AIX? Example, I want > to capture all output of the command " ps auxeww 7 <PID> ", but I can >...; may omit the rest so that it fits in the system defined output buffer. Thanks Janis, but I don't understand how to do that. My goal is to capture the entire output, which is longer than 2048 characters. Cheers! Janis Papanagnou wrote: > shpot4@yahoo.com wrote: > > Does anyone know the number of chars per line in AIX? Example, I want > > to capture all output of the command " ps auxeww 7 <PID> ", but I can > > see that it cuts off somewhere around 2048 chars? Is there somewhere I > > can set this value to be greater? Or is this a limitation

clock cycle per OP
Hello, here is an example found in most of the literature Base Machine (Reg / Reg) Op Freq Cycles CPI (i) (% Time) ALU 50% 1 .5 (33%) Load 20% 2 .4 (27%) Store 10% 2 .2 (13%) Branch 20% 2 .4 (27%) [ it can be found here as well http://engineering.dartmouth.edu/~engs116/lectures/engs%20116%20lecture%202-05f.ppt#275,16,Example: Calculating CPI Freq: stands for the OP occurence frequency Cycles: number of cycles needed for that Op to complete [run?] CPI: stands for cycles per instructions. I am confused about the number of cycles allocated to each basic machine operation. I thought they all take 1 clock cycle in pipeline processor (except when there is a hazard for instance). so load, store, branch are given 2 clock cycles and ALU one? Thanks you <xu_feng_xu@yahoo.com> wrote: > I am confused about the number of cycles allocated to each basic > machine operation. I thought they all take 1 clock cycle in pipeline > processor (except when there is a hazard for instance). so load, store, > branch are given 2 clock cycles and ALU one? I think it is a simplified model, used before pipelining is introduced to the students

How to limit outgoing mails per account per day
Hello there, We have sendmail 8.12 running on SuSE Linux ES 9.0. We would like to restrict our clients to send only 1000 mails per day per account. Is there any feature in this version of sendmail to implement this rule ? Any suggestion on this regard will be highly appreciated. Thanks, Sikkandar. On Feb 26, 5:34 am, sikkandar.u...@gmail.com wrote: > Hello there, > > We have sendmail 8.12 running on SuSE Linux ES 9.0. We would like to > restrict our clients to send only 1000 mails per day per account. Is > there any feature in this version of sendmail to implement... script would be the quick and dirty approach. -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Tue, 26 Feb 2008 02:34:33 -0800, sikkandar.uni wrote: > We have sendmail 8.12 running on SuSE Linux ES 9.0. We would like to > restrict our clients to send only 1000 mails per day per account. Is > there > any feature in this version of sendmail to implement this rule ? > Any suggestion on this regard will be highly appreciated. You might try <http://www.five-ten-sg.com/dnsbl> with a config file that only does rate limiting. -----BEGIN PGP SIGNATURE----- Version: GnuPG