Combining 2 different models

Hi there,
I need help regarding combining two mathematical models in such a way that the output of one becomes the input to the other. Can anybody suggest, how should I proceed? Thanks.
Further to the comments, Please find below the coding of the first model. Now after 30 iterations i plot the curves, which have been commented now. From the output (15) generated, I only want to use the first 6 values in my 2nd model.
clear all
close all
SteadySMSR1
clc
global Pt0 u u01 u02 u03 u04 u05 u06 u013 u0 counter s1 s2 s3 s4 s5 s6 s7 s8 s9 s10 s11 s12 s13 s14 s15 kg hw
u0 = [0.2355;0.0254; 0.0207;0.6145; 0.0943;0.0096;0.2356;00255;0.0205;0.6147;0.0940;0.0097;899;902;1];
u01=0.2501; u02=0.0075; u03=0.0022; u04=0.7221; u05=0.0083; u06=0.0098; u013=893; %***Inlet condition*****
u=u0;
tfinal=1200;
tinc=10;
tmesh=1:tinc:tfinal;
s1(1,1:length(tmesh))=0.2501;
s2(1,1:length(tmesh))=0.0075;
s3(1,1:length(tmesh))=0.0022;
s4(1,1:length(tmesh))=0.7221;
s5(1,1:length(tmesh))=0.0083;
s6(1,1:length(tmesh))=0.0098;
s7(1,1:length(tmesh))=0.2501;
s8(1,1:length(tmesh))=0.0075;
s9(1,1:length(tmesh))=0.0022;
s10(1,1:length(tmesh))=0.7221;
s11(1,1:length(tmesh))=0.0083;
s12(1,1:length(tmesh))=0.0098;
s13(1,1:length(tmesh))=893;
s14(1,1:length(tmesh))=893;
f1='Report1';
f2='Report2';
f3='Report3';
f4='Report4';
f5='Report5';
f6='Report6';
f7='Report7';
f8='Report8';
f9='Report9';
f10='Report10';
f11='Report11';
f12='Report12';
f13='Report13';
f14='Report14';
f15='Report15';
options = odeset('RelTol',1e-8);
counter=2;
waithandle=waitbar(0,' Step2 : ------ Dynamic Simulation ------ '); % Initialize waitbar
% ----- Solving the system of PDEs -----
while counter<32
if (counter+0.01<=32),
waitbar(counter/31,waithandle);
end
[t1 u1]=ode23s(@simulationMSR1,1:tinc:tfinal-1,u0,options);
s1(counter,:)=u1(:,1)';
s2(counter,:)=u1(:,2)';
s3(counter,:)=u1(:,3)';
s4(counter,:)=u1(:,4)';
s5(counter,:)=u1(:,5)';
s6(counter,:)=u1(:,6)';
s7(counter,:)=u1(:,7)';
s8(counter,:)=u1(:,8)';
s9(counter,:)=u1(:,9)';
s10(counter,:)=u1(:,10)';
s11(counter,:)=u1(:,11)';
s12(counter,:)=u1(:,12)';
s13(counter,:)=u1(:,13)';
s14(counter,:)=u1(:,14)';
s15(counter,:)=u1(:,15)';
load('ReportS','w');
a1=w(counter,1);
a2=w(counter,2);
a3=w(counter,3);
a4=w(counter,4);
a5=w(counter,5);
a6=w(counter,6);
a7=w(counter,7);
a8=w(counter,8);
a9=w(counter,9);
a10=w(counter,10);
a11=w(counter,11);
a12=w(counter,12);
a13=w(counter,13);
a14=w(counter,14);
a15=1;
u0=[a1;a2;a3;a4;a5;a6;a7;a8;a9;a10;a11;a12;a13;a14;a15];
Pt0=Pt0-(delP/L)*delz;
counter=counter+1;
end
close(waithandle);
% ----- Saves the results -----
save(f1,'s1');
save(f2,'s2');
save(f3,'s3');
save(f4,'s4');
save(f5,'s5');
save(f6,'s6');
save(f7,'s7');
save(f8,'s8');
save(f9,'s9');
save(f10,'s10');
save(f11,'s11');
save(f12,'s12');
save(f13,'s13');
save(f14,'s14');
save(f15,'s15');
% save(f16,'s16');
bbb=clock;
% ----- 3D plotts of the model -----
% figure(1);
% x=1:1:31;
% time=1:tinc:tfinal;
% z=0:14.35/30:14.35;
%
% figure(1);mesh(time,x,s1);title('CH4 mol fraction');
% figure(2);mesh(time,x,s2);title('CO2 mol fraction');
% figure(3);mesh(time,x,s3);title('CO mol fraction');
% figure(4);mesh(time,x,s4);title('H2O mol fraction');
% figure(5);mesh(time,x,s5);title('H2 mol fraction');
% % figure(6);mesh(time,x,s6);title('N2 mol fraction');
% figure(7);mesh(time,x,s13);title('Temperatre');
% s15(1,:)=s15(2,:)
% figure(8);mesh(time,x,s15);title('Activity');
% % figure(9);mesh(time,x,s16);title('Pressure drop');

 Akzeptierte Antwort

Andrew Newell
Andrew Newell am 14 Mai 2011

0 Stimmen

I'm a little unclear on what you mean by "values". I will assume each vector s1, s2, etc., is a value, so what you need is this:
f1='Report1';
f2='Report2';
f3='Report3';
f4='Report4';
f5='Report5';
f6='Report6';
load(f1,'s1');
load(f2,'s2');
load(f3,'s3');
load(f4,'s4');
load(f5,'s5');
load(f6,'s6');
Have I interpreted your question correctly?

2 Kommentare

Amjad
Amjad am 15 Mai 2011
What u presumed is right? It was helpful.
Having loaded the files the problem lies in the fact that each 's' is a vector. Now previously, in the 2nd model, I m having a vector of y=[y1 y2 y3 y4 y5 y6]. Now all these individual y's are scalar quantities. And there are numerous complex equations where they are used. So can you suggest further as to how can I replace it everywhere with the new 's' values. Secondly, 's' gives me a range of quantities and I only want to use the last iterated result.
Any suggestions on that, please. Thanks.
Andrew Newell
Andrew Newell am 15 Mai 2011
To answer your second question first: y = [s1(end) s2(end) etc.]. This leaves you with a vector, as before, so maybe you don't need to change your code. If you do, you could replace y by a matrix. As to how exactly you'd change the code, that may vary. I think the first thing you should do is get very familiar with matrix and vector operations. See, for example, http://www.mathworks.com/help/techdoc/math/f4-988203.html.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Andrew Newell
Andrew Newell am 11 Mai 2011

0 Stimmen

out1 = model1(in1);
out2 = model2(out1,otherVariables);

2 Kommentare

Amjad
Amjad am 14 Mai 2011
Thanks Andrew for a quick reply and am sorry for not replying earlier. Frankly speaking I was not able to understand your answer. Let me brief you a little. Each of my model is solved using fsolve and ODE23s and consists of 5 files. Now the part of the output set of values of model 1 is to be used as input to the second. When I solve the first one, I generate the plots, now I have stopped them but how to make 2nd model read a particular value is a problem.
In the past 2 days, one of my friends suggested to define 2 functions associated with these models OR alternatively make 2nd model read value from a workspace file. I am not able to grasp both of these. If you have some elaboration on these or your own solution, please let me know. Thanks.
Andrew Newell
Andrew Newell am 14 Mai 2011
The problem is, you provided so little information in your question that my answer could easily have been what you needed. There still isn't enough information to answer your question. I suggest that you go to the top of this page, click on "Edit", and edit your original question. Provide the code that produces the output or the format of your output files, let us know what information you need for the second model, and then we might be able to get somewhere.

Melden Sie sich an, um zu kommentieren.

Kategorien

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

Community Treasure Hunt

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

Start Hunting!

Translated by