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

## 2 variables and if statements  6-Contributor

## 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  23-Emerald II
(To:GvanBoven)

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  6-Contributor
(To:LucMeekes)

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 use Prime 3.1  23-Emerald II
(To:GvanBoven)

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  20-Turquoise
(To:GvanBoven)

Hi,

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