Can someone help me to redefine a variable in a for loop or get me moving in the right direction? I am new to Mathcad.
I am calculating a standard step gradually varied flow profile in a steep pipe. Pages 1 and 2 are inputs and creating functions that define the geometric properties of the open channel flow in terms of flow depth (y)
In the solver block is the energy equation with upstream energy on the left and downstream energy + friction loss on the right. I want solver block to find the downstream depth (yd) that makes those sides equal, which I get. (note: the velocity V and friction slope Sf terms in the equation are functions of y, so I can't solve algebraically)
My problem is I need to repeat that step by step along the pipe. for simplicity now I have (100) 1 ft steps in a 100 foot long pipe but those values are arbitrary until I can get the for loop working.
In the for loop, for every step I want to redefine yu equal to yd. I want to be able to plot flow depth (y) vs station of the pipe (X). It should look like the S2 profile. I tried to use the yU←yD within the for loop to accomplish this, but it seems to not update the depth yu in the solver block. Most of the help available from mathcad is very basic with a claim that "programming in mathcad is intuitive and easy" so I may just be an idiot!
Solved! Go to Solution.
I think you intended to use the functions in the solve block equation and not just their values of the first yD and yU you calculate in front of the solve block.
Furthermore the functions you use for yD and yU are the very same, so there is no need to define an extra function for each.
That way we get
and
In case you intended to let the iteration run until yD=yU you could use the root command to get that value
But if this value would have been the goal, all you need would be
Concerning the plot you were talking about I am not sure if you had something like this in mind:
I don't have Prime 8 installed so the attached file is in Prime 11 format.
I additionally attach a pdf print so you can see all definitions done.
It looks to me that you tried to parametrize the solve block, but when you wrote "f(x):=..." you are using an argument "x" which does not occur anywhere in the solve block equation, so you get the very same result will be result for any function argument "x" you provide.
How should Prime know that you mean yU to be changed?
Maybe you found in the help Parameterizing Solve Blocks.
If you want to use a different value for yU every time you call the solve block then you simply have to use yD as function argument:
Now you can do this iteration a couple of times (N times, if you like) using a for-loop:
I have no experience in your field of work but its noticeable that the values get negative right after the first step. Was this to be expected?
Could it be that in the solve block you rather should use the FUNCTIONS VU(yU), SfU(yU) etc. instead of the scalars with same name (which overwrite the functions and make then inaccessible)?
BTW, you are using Prime 9 and you defined X as being a vector using an undocumented trick (defining a range and evaluating it numerically in the same region). This trick does not work in Prime 10 and later versions. In Prime 11 PTC provided a new function "vec" which allows to conveniently create a vector using the same values (first, second and last) as you do when creating a range.
I think you intended to use the functions in the solve block equation and not just their values of the first yD and yU you calculate in front of the solve block.
Furthermore the functions you use for yD and yU are the very same, so there is no need to define an extra function for each.
That way we get
and
In case you intended to let the iteration run until yD=yU you could use the root command to get that value
But if this value would have been the goal, all you need would be
Concerning the plot you were talking about I am not sure if you had something like this in mind:
I don't have Prime 8 installed so the attached file is in Prime 11 format.
I additionally attach a pdf print so you can see all definitions done.
Thank you both Werner_E and AlanStevens! These solutions are very helpful.
I suffer from chronic function confusion haha.
I appreciate that you included the pdfs since apparently MATHCAD won't open across versions.
-Steve
apparently MATHCAD won't open across versions.
Yes, unfortunately that is true.
In an effort to optimize profits, PTC has decided that, on the one hand, a Prime version should not be able to open files from newer versions and, on the other hand, that no Prime version should offer the option of saving files in the format of older versions (with the loss of newly added features, of course).
Here's a version done in Prime Express, (also 11, so pdf attached and image shown be;low).
