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

'if' function on MathCAD

TN_9676358
6-Contributor

'if' function on MathCAD

Hi everyone,

I did this project on Matlab so I'm not sure how it should be at MathCAD. I have 1 condition

 

Td(t) = if(t<theta,To,T*(t-theta).

 

My professor got the result from MathCAD, I'm not sure how do we use if function here?

 

I also attached the file in this post, the issue was occur at scenario 3.

 

Thank you so much again,

 

1 ACCEPTED SOLUTION

Accepted Solutions

You did not specify an initial condition for T.sf, so I used a random value (T.sf(0)=100°F).

Obviously you want it to change to T.sf(0)=120°F,

View solution in original post

17 REPLIES 17

You only show scenario 1.

 

But  the units for hc include capacitance instead of temperature: 

FredKohlhepp_0-1602951575197.png

Try  

FredKohlhepp_1-1602951768023.png

 

Hello

I fixed that already. I think I attached the wrong file. 

 

Would you please help me to take a look again please?

 

Thank you so much

Your function T.d creates a unit mismatch and is incomplete.

For t=1 minute the result is a temperature but for t<1 minute the result is temperature times time and for t>1 minute there is no result defined:

Werner_E_0-1602952564175.png

BTW, what you wrote

Td(t) = if(t<theta,To,T*(t-theta)

could be done the very same way in Prime, too. Mathcad and also Prime offer two ways for an if. The if-statement in a program as you had used and the if-function (similar to the if function in a spreadsheet).

To duplicate in your program what the if-function does, you would have to use the "else" statement instead of the second "if". But the unit problem remains.

 

 

 

TN_9676358
6-Contributor
(To:Werner_E)

Hello,

Td = T(t)(t-theta). the T(t) was defined in the ODEs equation. so the purpose is finding T(t) using the first 3 ODEs, then plug T(t) to "if" function. 

He said I could define Td like he did. But i'm not sure

T(t) returns a temperature, t and theta are time, so the result of T.d(t) would be temperature * time. Is this really what its supposed to be? I guess - no.

 

If the "original" was done with real Mathcad (version 15 or below), then it had to be done without units because odesolve-blocks did not work with units. Thats the reason you won't expirience the error in that version.

 

I am not sure if it makes sense, but you could get rid of the time by simply dividing by s

Werner_E_0-1602954338493.png

But you have a discontinuity at 1 min, which may be the reason for the odesolve-block after its definition to fail with some kind of strange error.

Werner_E_2-1602954499043.png

 

 

 

TN_9676358
6-Contributor
(To:Werner_E)

Hello,

I think I wrote it wrong. Td is the temperature of T(t) at time (t-1 min).

 

Example, Td = T at (time-1) which mean at t=0 min, T(t)=120, and at t=1, T(t) = 119. Td supposed to be the same as T at t=0 min and t=1 min

 

However, there is one minute delay so at t=1mins, Td = 120, which is the last value of T(t). and Td won't generate any reading at t=0

 

I hope this makes sense.

 

I wrote in matlab is for i=1:100, Td=T*(i-1), i is time range in minute.

Thank you so much!

You mean something like this:

Werner_E_1-1602955017748.png

I guess it would be better to replace "322.039 K" by "T(theta)".

 

According the solve block: You have an equation for a function T.sf there which you do not solve for. get rid of it and the solve block should work OK:

Werner_E_2-1602955635062.png

 

 

 

TN_9676358
6-Contributor
(To:Werner_E)

Spoiler
 

Hello,

that is what I did in scenario 2. now i need to solve for Tsf in scenario 3. Do you think if I specify in scenario T(t) will it be able to read the value from last run in scenario 2?

Whatever variable or function name you use, Prime will use the last definition of it.

But as you use T(t) as a function to solve for in your new solve block, Prime can't (and shouldn't) use last definition of it from the previous solve block.

TN_9676358
6-Contributor
(To:Werner_E)

I will remove the first 3 odes and will just define Td based on T(t) from last run. I hope it work


@TN_9676358 wrote:

I will remove the first 3 odes and will just define Td based on T(t) from last run. I hope it work


It does 😉

But the interval in the solve block for T must be a bit larger than the one for T.sf:

Werner_E_0-1602961782609.png

It has to do with the numerical derivatives the algorithm uses.

Werner_E_0-1602961999318.png

 

 

 

TN_9676358
6-Contributor
(To:Werner_E)

sorry i just read the message 😞 The graph I'm looking for looks differently. Im not sure what wrong. everything will need to start at T=120F. Do you have any ideas where am I wrong?

You did not specify an initial condition for T.sf, so I used a random value (T.sf(0)=100°F).

Obviously you want it to change to T.sf(0)=120°F,

TN_9676358
6-Contributor
(To:Werner_E)

Hello,

So Td and Tsf will start the first point at t=1, I specify the value of Tsf(0)=120F and they say the ODE range is larger. I believed for Td, because Td won't start until t=1, I think if t<0, there is no Td value. 

Let me attached the new files for you.

 

I will need to specify both Tsf and Td starts at t=1 min.

 

Thank you so so much for your help

 

 

TN_9676358
6-Contributor
(To:TN_9676358)

and the graph supposed to look like this.

 

Thank you so much.

 

TN_9676358
6-Contributor
(To:TN_9676358)

Spoiler
Spoiler
 

oh no I didn't get Tsf :(, I just got Td(t) :((

TN_9676358
6-Contributor
(To:TN_9676358)

i got it. thank you so much.

Announcements
Check out the latest
Mathcad Tip
"PTC Mathcad 15 / Prime 1-6 Update."