Differential Equations and Variables

Hello,
I would like to know if it's possible to execute and store results from a simple linear differential equation pulling one of the variable from an external file and storing/saving the results in a different file keeping the same formatting.
To better explain, here is what I am trying to do:
I have a table in excel, column 'I' is one of the variable in my model where values change. I need to compute the results of my differential equation so that the result can be inserted next to each of the cells of 'I'
'I' is the variable which would actually vary in my case
my diff equations is: dx/dt=I(S+A).
Thank you regards J

 Akzeptierte Antwort

Yao Li
Yao Li am 10 Apr. 2013

1 Stimme

I=xlsread('Path\filename.xlsx','I:I');
%add your own codes to solve the equation
n=length(I);
range=strcat('J1:J',num2str(n));
xlswrite('Path\filename.xlsx',output,range);

7 Kommentare

J
J am 10 Apr. 2013
Thanks Yao, but I am having problems implementing that and I am not sure what is wrong. I am trying to solve the diff equation with ode45 and this is what I have done:
now the equation is dx/dt=I(S*A*x). so i am trying to see the evolution of x with time
I=xlsread('c\fmlab\testing.xlsx','I:I');
f=inline I(S*A*x). ode45...
but it wont work. Any ideas? Is it the ode45? thank you. J
Yao Li
Yao Li am 10 Apr. 2013
Is I*S*A constant or varies with time?
J
J am 10 Apr. 2013
Hi Yao,
'I' is a column of about 10000k different volumes which are the number of n i would need for the model to output so they don't variy over time.
but S and A are as they are pressure and temperature readings taken every 30 mins over 48 hrs in total. So i have 96 x 2 reading in total for S and A in my excel spreadsheet.
Thank you. J
Yao Li
Yao Li am 10 Apr. 2013
If you can obtain the analytic expression of I*S*A with respect to time, it is easy to solve the equation.
If you can't, I think, actually, integration is some kind of method to calculate the sum of the variables. S and A are samples of the corresponding variables. The solution of the equation depends on how to use these samples. For example, S is considered as constant during every 30 mins or varies linearly and the sampling point is considered as a mean value, etc
J
J am 10 Apr. 2013
Hi,
unfortunately I can't. I'll probably have to think a bit over that. If I keep S and A as a constant - let's say I just consider their columns for row 1 in excel. Would you know how to input that so that it output the results correctly? Thank you.j
Yao Li
Yao Li am 10 Apr. 2013
Bearbeitet: Yao Li am 10 Apr. 2013
Assuming I, S and A are stored in columns A,B and C, respectively. The results x will be stored in column D. Hope the codes below can help:
data=xlsread('Path\filename.xlsx','A:C');
I=data(:,1);
S=data(:,2);
A=data(:,3);
time=(30:30:48*60)';
n=length(time);
range=strcat('D1:D',num2str(n));
x0=1;
x(1)=x0;
for i=2:1:n
c(i)=trapz(time(1:i),(I(1:i).*(S(1:i)+A(1:i))));
x(i)=x0*exp(c(i));
end
xlswrite('Path\filename.xlsx',x',range);
Pls. pay attention to the x' in the last row.
Yao Li
Yao Li am 10 Apr. 2013
Actually, I think you can also import your data to Simulink to obtain your outputs. If you think it's OK, you can send the Excel file to me by email.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Hilfe-Center und File Exchange

Gefragt:

J
J
am 10 Apr. 2013

Community Treasure Hunt

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

Start Hunting!

Translated by