cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can change your system assigned username to something more personal in your community settings. X

Help for iteration

NandaV
7-Bedrock

Help for iteration

Hey guys,

 

I'm new in Mathcad and I'm doing my thesis now. I have some trouble finding how to do iteration in Mathcad.

So in my file, I have a reactor of 250 m. And I want to know how the concentration changes.

But, I want the simulation to run for >1 cycle. Which means I have to define a way to make the Cout (concentration out) from previous cycle, as a value for the Cin(2) concentration in of the next cycle. These are for both liquid and gas concentration.

 

So in summary I want to make a loop of :

COlin (x+1) = COlout (x)

COgin (x+1) = COgout (x) + COgin (x)

 

Help guys 😞

Thank you in advance

ACCEPTED SOLUTION

Accepted Solutions


@NandaV wrote:

 

I mean now I have the for loop cycle after the 1st cycle derivation.

 


No. I just left an example of a single cycle so you could see that changing the Odesolve block to a function didn't alter the calculation.  In the attached I've removed this!

 


@NandaV wrote:

 

Also, isn't now the system taking the value from previous x point, so the COlin (x) = COlout (X-1) instead of per cycle? 


No. Each cycle covers all values of x before updating the inlet values for the next cycle.  This is because all values of x are considered by the Odesolve function which is called just once per cycle.

 

Alan

View solution in original post

28 REPLIES 28
Fred_Kohlhepp
23-Emerald I
(To:NandaV)

What you have is two coupled first order differential equations.  Your "Given" block is missing its closure.

 

Given needs to be a closed block, in your case with Odesolve.  Review help on solving differential equations--there should be an example that is directly applicable.

Hey Fred,

 

Thanks for your reply. What do you mean by closed solve block?

Because in that file i'm using the "Given" which means I have the solve block already?

Now i'm just confused in trying to figure out how to loop the result as an input of the next derivation.


@SavitriN wrote:

Hey Fred,

 

Thanks for your reply. What do you mean by closed solve block?

Because in that file i'm using the "Given" which means I have the solve block already?

Now i'm just confused in trying to figure out how to loop the result as an input of the next derivation.


A solve block opens with "Given".

It closes with "Find" or with "Minerr" or with "Minimize", or with :Maximize," or with "ODEsolve" (maybe I've missed a couple.)

 

Yours doesn't close.

1.png

 

 

 

Yes I did closed it with the Odesolver…

As you can see in my attached picture.

Fred_Kohlhepp
23-Emerald I
(To:NandaV)

So you should have two functions of the two parameters.  What happens if you type C.O2lSS(2m), or try to plot C.02lSS(x) vs x?

Fred, in case you can't open and view the OPs worksheet, here is a pdf print of it.

He had already solved the ODE system and I have no clue which iteration he is asking for.

 

NandaV
7-Bedrock
(To:Werner_E)

Hey Werner & Fred, What i meant by iteration is a for loop.

I have a system with a fix inlet and outlet which has a length of 250 m.

1 cycle means that the system run from inlet into outlet for 1 time.

When i run the derivation, i use intial value of Clin (concentration liquid in) and Cgin (concentration gas in) which will give a result of Clout (concentration liquid out) and Cgout (concentration gas out).

For the 2nd cycle, i want to use Clout for the initial value instead of Clin. And for the gas, i will always want to use Cgin as intial value (fresh air).

Clin1cycle = Clin & Clin2cycle = Clout1cycle & Clin3cycle = Clout2cycle, etc.

Cgin1cycle = Cgin2cycle = Cgin2cycle = Cgin

 

However, i dont know how to translate in into for loop command in mathcad.

That's what i was trying to ask.

Thank you

Is the attached what you are looking for?  

Is the attached what you are looking for?  

 

Alan

Hey Alan,

 

I think yes but i do not understand the outliq (L.total) and outgas(L.total) term and do i have to add inside the ODE solver the determination of cycles ?


@NandaV wrote:

Hey Alan,

 

I think yes but i do not understand the outliq (L.total) and outgas(L.total) term and do i have to add inside the ODE solver the determination of cycles ?


The number of cycles is set by the variable ncycles that is assigned immediately before the program structure. I've arbitrarily set ncycles to 5.  You will need to set it to whatever is appropriate for your problem. 

 

I've assumed that for given inlet values of gas and liquid, the calculations are done for every section (x) from 1 to Ltotal. Within the program I've used dummy variables outliq and outgas to calculate  the values of CO2l and CO2g for every section (x) (via the Odesolve block, which is now a function of the inlet values).  The inlets for the next cycle, inliq and ingas  are then set to the outlet values of outliq and outgas for the previous cycle, hence they are set to the last section values, namely outliq(Ltotal) and inliq(Ltotal). The final values of outliq and outgas each a vector of length Ltotal, are then returned to CO2lSS and CO2gSS respectively.

 

Alan

 

Edit:  My description above is not completely correct!  outliq and outgas are not vectors, but functions (of x), so that CO2lSS and CO2gSS are also functions.

Alan

 

(For some reason my previous reply was posted twice!!)

Ah.. okay I understand. But is it possible to do the derivation only once?

I mean now I have the for loop cycle after the 1st cycle derivation.

 

Also, isn't now the system taking the value from previous x point, so the COlin (x) = COlout (X-1) instead of per cycle? (I hope you understand what I meant).


@NandaV wrote:

 

I mean now I have the for loop cycle after the 1st cycle derivation.

 


No. I just left an example of a single cycle so you could see that changing the Odesolve block to a function didn't alter the calculation.  In the attached I've removed this!

 


@NandaV wrote:

 

Also, isn't now the system taking the value from previous x point, so the COlin (x) = COlout (X-1) instead of per cycle? 


No. Each cycle covers all values of x before updating the inlet values for the next cycle.  This is because all values of x are considered by the Odesolve function which is called just once per cycle.

 

Alan

Yes. I understand now. Thank you so much Alan!

Hey Alex, 

 

So, there is another approach i should look into. Instead of coupling the CO2lSS & CO2gSS in one derivation.

I have to first solve the CO2lSS with ode solver and resulted in CO2lSS(x).

And from there i substitute into the equation of CO2gSS(x) equation, where inside the equation there the CO2gin and CO2lin which has to equal to the CO2lout (x-1) and CO2gout (x-1).

 

So i have to make the new For loop, i tried but it still gives error. Do you mind helping me with this?

I would really appreciate it.

 

Thank you. 

Something like the attached perhaps?

 

It would help if you were (1) to specify the units of all the constants and variables, and (2) to show a system diagram.  I would then be in a much better position to check my interpretation of what I think you are after!

 

Alan

 

 


Thanks for the reply. 

 

So, the re-circulation that i needed to simulate is the one presented above. The concentration in liquid is solved first by the ODE solver and results in CO2l(x) to simulate each concentration in every x point. Then, the CO2g(x) can be found by substitution.

 

I'm not sure should i do the for loop for gas and liquid in 1 command, or should i do it separately (like you did in previous file). I hope it makes thing clearer...

 

 

 

Notice that your liquid phase equations have an analytical solution, so, alternatively, you could do the calculations as in the attached

 

Alan

Okay, i will try that. Thank you very much!!

Hey Alan,

 

Looking at the result curve, i'm having trouble now in plotting the result.

I can only plot the first cycle and the last cycle.

Which means if I set n>2 cycles, I can not see and plot the curve for the middle between cycles 2 and last cycle.

Do you mind helping me again to solve this problem?

 

Thanks

See the attached.

 

Alan

 

Dear Alan,

 

Thank you very much!

Hey Alan,

It's me again haha. So I was wondering, from previous iteration it is correct that the value from previous cycle got taken up as an input value for the next cycle. However, I noticed that actually the liquid and gas derivation is not connected, while it's supposed to be connected. So, the liquid derivation has to take the new COgin as well, and same for the gas substitution has to take new COlin. While now, the new COgin value only used for gas derivation and the new COlin value only used for liquid derivation.

 

I made the new iteration as attached, do you think it's correct?

 

Thanks 


@Werner_E wrote:

Fred, in case you can't open and view the OPs worksheet, here is a pdf print of it.

He had already solved the ODE system and I have no clue which iteration he is asking for.

 


Thanks Werner,

 

Smath will open parts of xmcd drawings (not Prime), but it just skips what it doesn't understand (things like "Find" and graphs.  So I can speak to some of the problems, but not what I can't see. . .

LucMeekes
23-Emerald III
(To:NandaV)

Maybe you should look here.

https://community.ptc.com/t5/PTC-Mathcad/Integration-Solver/m-p/578494#M183033

It deals with (what appears to be/almost?) the exact same problem.

 

Success!
Luc

Hey Luc, unfortunately, that is my other account which I forgot the password..

So that is still my case haha :'')

Fred_Kohlhepp
23-Emerald I
(To:NandaV)

There's an old method in Mathcad that mimics Euler's approximation to ODE's.  This might work for you.

Capture.PNG

(set ORIGIN to 1)

Announcements

Top Tags