Get Help

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Community
- :
- PTC Mathcad
- :
- PTC Mathcad
- :
- Re: 'if function on MathCAD

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

10-17-2020
11:14 AM

10-17-2020
11:14 AM

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,

Solved! Go to Solution.

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

10-19-2020
07:00 PM

10-19-2020
07:00 PM

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,

17 REPLIES 17

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

10-17-2020
12:23 PM

10-17-2020
12:23 PM

Re: 'if function on MathCAD

You only show scenario 1.

But the units for hc include capacitance instead of temperature:

Try

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

10-17-2020
12:27 PM

10-17-2020
12:27 PM

Re: 'if function on MathCAD

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

10-17-2020
12:36 PM

10-17-2020
12:36 PM

Re: 'if function on MathCAD

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:

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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

10-17-2020
12:57 PM

10-17-2020
12:57 PM

Re: 'if function on MathCAD

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

10-17-2020
01:01 PM

10-17-2020
01:01 PM

Re: 'if function on MathCAD

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

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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

10-17-2020
01:11 PM

10-17-2020
01:11 PM

Re: 'if function on MathCAD

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!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

10-17-2020
01:27 PM

10-17-2020
01:27 PM

Re: 'if function on MathCAD

You mean something like this:

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:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

10-17-2020
01:32 PM

10-17-2020
01:32 PM

Re: 'if function on MathCAD

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?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

10-17-2020
01:39 PM

10-17-2020
01:39 PM

Re: 'if function on MathCAD

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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

10-17-2020
01:41 PM

10-17-2020
01:41 PM

Re: 'if function on MathCAD

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

10-17-2020
03:11 PM

10-17-2020
03:11 PM

Re: 'if function on MathCAD

@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:

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

10-19-2020
06:57 PM

10-19-2020
06:57 PM

Re: 'if function on MathCAD

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?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

10-19-2020
07:00 PM

10-19-2020
07:00 PM

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,

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

10-19-2020
07:12 PM

10-19-2020
07:12 PM

Re: 'if function on MathCAD

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

10-19-2020
07:21 PM

10-19-2020
07:21 PM

Re: 'if function on MathCAD

and the graph supposed to look like this.

Thank you so much.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

10-19-2020
07:26 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

10-19-2020
09:27 PM

10-19-2020
09:27 PM

Re: 'if function on MathCAD

i got it. thank you so much.