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
- :
- 2 variables and if statements

Options

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

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

Showing results for

Highlighted
##

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

06-11-2018
11:17 AM

06-11-2018
11:17 AM

2 variables and if statements

*Hello eveyone,*

*I am trying to calculate erosion on clay levee's where the soil protection has failed. To do this I need to calculate 2 variables. The way the variables are calculated differs depending on one of the variables that I need to calculate... Hope this makes sense. To illustrate I added a picture with a program where the different ways of calculating and the statements for each phase are given.*

*I am trying to calculate the variable cotat and hklif. So in the case cotat < 8 it would be the equition from the first if statement.*

*Other variables like Hs dk hb etc are known cause they are input in the sheet.*

4 REPLIES 4

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

06-11-2018
11:47 AM

06-11-2018
11:47 AM

Re: 2 variables and if statements

OK. En wat is dan het probleem?

Verder is het handig(er) als je (ook) je Mathcad Prime sheet aanhangt, in plaats van / naast een plaatje.

En vertel even met welke versie van Prime je werkt.

Succes!

Luc

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

06-11-2018
11:54 AM

06-11-2018
11:54 AM

Re: 2 variables and if statements

Hi,

You can return two variables *cotat and hklif from your program by placing them as two elements of a vector.*

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

06-14-2018
06:10 AM

06-14-2018
06:10 AM

Re: 2 variables and if statements

Thanks for the reaction

I want to calculate 3 variables (Hterras Hkliff and cotat) I need to start with the guess value cotat=8. This has to be done itterative.

I tried to put all the boundary conditions in 1 program but my mathcad knowledge is still a bit limited and I do not know how to correclty make this program and solve block work.

I added the MC file.

I use Prime 3.1

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

06-14-2018
12:28 PM

06-14-2018
12:28 PM

Re: 2 variables and if statements

Please exercise the usage of a solve block with some simple examples (refer to Prime help files), to get yourself familiar with the concept.

Note that you should NOT need to program the search algorithm to find answers using a solve block. Iteration is part of the inherent process. All you need to do is provide the guess values and the constraints; the solve block should do the rest.

In your constraints section is what seems a function y(x)=... for that to work, either x must be known, or it is a variable the value of which is to be found. In your case x is unknown (not defined prior to its usage) and is not in the list of find(). So Prime complains for good reasons.

Then you should be aware that defining a function in sections (with if's) can pose problems for the iteration. If the function results in gaps (e.g. "if x>0 then 5 else -3") it makes certain function results impossible, and finding a suitable solution hard, if not impossible. I don't know if that's the case with your program, because I cannot evaluate it {I'm limited to Prime Express, it's free=gratis, but then lacks some interesting features, such as programming and solve blocks}.

Finally your constraint compares y(x) with the result of the program that returns a vector with three elements. This means that y(x) must be defined (beforehand) as an array with three elements.... It isn't. And there is no function y() defined either.

My advice: work through some simple examples with solve blocks, to get a better understanding of the usage of solve blocks. If you have trouble at any point in doing that, don't hesitate to ask for guidance here.

Success!

Luc

Top Tags