Hello,
I am trying to work with my final solution but Mathcad is saying the variable is undefined even though it's being defined earlier. I have attached the file. Any help will be really appreciated.
Thank you,
Faisal
Solved! Go to Solution.
It's not alpha.1, but psi.ini that is undefined.
Mathcad was never superb at locating exact positions of errors.
Success!
Luc
Thank you for your response. What should I do to make it solved
Define psi.ini, or take it out of the function, if you don't need it, but I guess you have it in because it serves a purpose. Maybe you are mistaken and meant psi.0 ....?
One thing that will help you, is if you take the immediate evaluation off of the end of the definition.
Just define the psi.new function (in terms of K() and the rest), but do NOT put an equals sign at the end.
See if that goes without error. If there are errors in there, solve those first. Then you can evaluate the function.
Success!
Luc
Thank you for your reply. I was trying to generate a final outcome based on successive increments in an if-else statement but it was saying that it did not converge due to infinite recursion. How will I approach this.
Its in no way clear to me what you are trying to do.
Some observations:
"Lambda" is a vector with just one element - is this whats it supposed to be?
"I" is a vector of a couple of values so what do you expect as outcome of your last function? A vector or a scalar.
Main problem is that n is a range and so the condition n=0 in your function never is true leading to an infinite recursion.
Is one of the following two function what you are looking for?
or
Thank you very much Werner_E. I wanted to be like this.
@fahmed-2 wrote:
Thank you very much Werner_E. I wanted to be like this.
Hmm - whichever of the two recursive function I provided you are talking of - there is an easier an direct approach for both of them:
Thank you very much for your reply. I am still learning Mathcad and trying to know the syntaxes to make my coding nice and efficient. I liked the first one that you have helped me out. This calculation set was done for one value of Z, is it possible to make it happen for a set of Z's and get segmentwise outputs for each Z. I can make it in a way which might be too long and not great.
You mean you have a vector of Z-values and each Z-value should calculate a 9 element vector?
What kind of data structure do you expect the result to be? A 9xn matrix or a nested vector?
I mean I have a vector of Z-values and each Z-value should calculate an m element vector? Here, m is the number of rows/values in the "I" vector. I need to have an nxm matrix where each column represents one depth
Here is an approach which returns a nested vector
Worksheet in P4 format attached
The (kai subscript "0") should not be constant. It will change the way as you have shown me in the if else loop. I am trying to do this whole calculation set for an n element "Z" vector where the "I" is also an m-element vector.
I can do the whole in only one column vector but I am trying to implement it in different columns where each column represents one depth. I have attached my work
Are these really the correct values you need?
If yes, then the calculation can be simplified and corrected so the result is a true vector:
Now we can go ahead and create a function which returns a matrix - one column for every value of Z. Again, Z.new should be a vector, not a range. That way the result is a true vector/matrix and we can use it to build a table, export the values, ....
Worksheet in format P5 attached
Thank you very much again Werner_E. This works like a magic. I am really thankful. In the final stack, how can I get a value for a particular column and row. For example, if I need to find the value at 3m depth for rainfall of 0.5 mm/hr. I can do for a single column or, a single row but not at a particular element.
@fahmed-2 wrote:
Thank you very much again Werner_E. This works like a magic. I am really thankful. In the final stack, how can I get a value for a particular column and row. For example, if I need to find the value at 3m depth for rainfall of 0.5 mm/hr. I can do for a single column or, a single row but not at a particular element.
Not sure if I understand your problem.
You may use normal matrix indices to access single elements:
You can even use the table T I created to define an interpolation function so you can evaluate it at arbitrary values for I and Z or plot the 2D-surface.
The routine in the attach uses simple linear interpolation but you may use spline interpolation as well.
Thank you. My work involves to do a cubic spline interpolation. Should I try with a cubic spline and then use interpolation or, there is a smarter way.
Prime has (among many) a cubic spline function (cspline.) It will create a function that is an interpolation between knots.
Thank you very much. Should I use as interp(cspline(x,y),x,y,x1)
@fahmed-2 wrote:
Thank you. My work involves to do a cubic spline interpolation.
You never mentioned that you will be after interpolation so far
Should I try with a cubic spline and then use interpolation or, there is a smarter way.
The spline already IS an interpolation!
There is not much you'll have to change if you want to replace my linear interpolation by spline interpolation.
You also may want to know that Mathcad knows three different types of cubic splines (the difference is the behaviour at the end points).
Thank you very much for your email. My work has many pieces and parts and I am going one by one and approaching it. I have been working for almost 3 hours with this problem and might take some more time also. I myself also am trying to come up with various approaches and I truly appreciate your help towards my concern.
Is there a way to get the absolute values of a vector. I know the scalar part.
One way to do it:
You used try-error statement and mentioned as trying the absolute if not then just return the value. What does this logic signify. And finally, you vectorized the whole to make the output. Can you please tell me why was it done like this. Thank you
Try and catch was used because your matrix contains a cell with a text (upper left) which would otherwise throw an error when the absolute value is applied.
Vectorization is always the thing to do when you apply calculations on a vector or matrix which is supposed to work not on the whole vector/matrix but on every single element of it. In case of this example you could omit the explicit vectorization because Mathcad will apply automatic vectorization anyway but its a good idea to ALWAYS use explicit vectorization when you want it to be done and don't rely an Mathcads automatic one.
Thank you very much Werner_E. I am learning a lot from your help