Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X
Hi everybody,
with the help of Stuart Bruff I managed to get the file I uploaded here. Now I have a task, but don`t know if it is possible in MathCad, and when it is - how...
I wish to iterate the four constants (kic, kisc1, kisc2 and kQ) over a certain range, solve the set of equations and write the matrix (kic kisc1 kisc2 kQ Rqt) for each possible set of these k`s into a file. What I managed up to now is the variation of all k`s with l1, but I want to change them independently. My first try was to use several for-loops (one for each k), but I had too many problems and nothing did work, so I have nothing to show here.
Can anybody tell me if I should try further on, or if I can stop because it isn`t possible at all?
Thank you in advance,
Katharina
Solved! Go to Solution.
Katharina Hunger wrote:
Hi Stuart,
I can open the file now. Thank you! I will have to have take a closer look to try to understand what you did there.
But this I recognised immediately: the first array in the for-loop is red and I get this message:"The expression to the left of the equal sign cannot be defined."
I tried to define arrays this way before, and also got this message. I thought that I did something wrong and that I have to define arrays some other way in a program, but now I fear that it is a problem of me using the student version and not the professional version. Is that possible?
Greetings,
Katharina
Hi Katharina,
I'm not sure what you're seeing, but I dug out a copy of M2000. It doesn't like the parallel assignment, so I replaced it with a line-by-line approach as, I think, was intended for the programming (there's no need for it in a for loop). It now works in M2000, so it should work in M2001; I don't think it being a Student Edition makes a difference.
Stuart
Katharina Hunger wrote:
Hi everybody,
with the help of Stuart Bruff I managed to get the file I uploaded here. Now I have a task, but don`t know if it is possible in MathCad, and when it is - how...
I wish to iterate the four constants (kic, kisc1, kisc2 and kQ) over a certain range, solve the set of equations and write the matrix (kic kisc1 kisc2 kQ Rqt) for each possible set of these k`s into a file. What I managed up to now is the variation of all k`s with l1, but I want to change them independently. My first try was to use several for-loops (one for each k), but I had too many problems and nothing did work, so I have nothing to show here.
Can anybody tell me if I should try further on, or if I can stop because it isn`t possible at all?
Thank you in advance,
Katharina
Hi Katharina,
I haven't had time to look at the bit of the worksheet that reads/writes from file, but is the bit at the bottom of the attached worksheet sort of what you're after for the iteration over variables?
It uses a utility function, vec, that I wrote to quickly generate sequences. I'm not sure if it works in your version of Mathcad. If not, it should be fairly easy to replace it.
This would probably be a lot easier, and more general, if Mathcad had a proper multi-dimensional array facility (particularly indexing), but a lot can be done with nested arrays.
Stuart
Hi Stuart,
unfortunately I again can`t open your file (MathCad 2001, Student Version).
When I started this project I had expected that MathCad can handle multi-dimensional arrays. But I guess I am not the first person who would like that 🙂
Greetings,
Katharina
Katharina Hunger wrote:
Hi Stuart,
unfortunately I again can`t open your file (MathCad 2001, Student Version).
When I started this project I had expected that MathCad can handle multi-dimensional arrays. But I guess I am not the first person who would like that 🙂
Greetings,
Katharina
Hi Katharina,
OK, I thought I had saved it in 2001 format. Try the attached. It's in M2000 format and I'm not sure how that will save some items ... it should be OK.
Stuart
Hi Stuart,
I can open the file now. Thank you! I will have to have take a closer look to try to understand what you did there.
But this I recognised immediately: the first array in the for-loop is red and I get this message:"The expression to the left of the equal sign cannot be defined."
I tried to define arrays this way before, and also got this message. I thought that I did something wrong and that I have to define arrays some other way in a program, but now I fear that it is a problem of me using the student version and not the professional version. Is that possible?
Greetings,
Katharina
Katharina Hunger wrote:
Hi Stuart,
I can open the file now. Thank you! I will have to have take a closer look to try to understand what you did there.
But this I recognised immediately: the first array in the for-loop is red and I get this message:"The expression to the left of the equal sign cannot be defined."
I tried to define arrays this way before, and also got this message. I thought that I did something wrong and that I have to define arrays some other way in a program, but now I fear that it is a problem of me using the student version and not the professional version. Is that possible?
Greetings,
Katharina
Hi Katharina,
I'm not sure what you're seeing, but I dug out a copy of M2000. It doesn't like the parallel assignment, so I replaced it with a line-by-line approach as, I think, was intended for the programming (there's no need for it in a for loop). It now works in M2000, so it should work in M2001; I don't think it being a Student Edition makes a difference.
Stuart
Hi Stuart,
this really looks good. But I still have some questions:
The first two arrays at the bottom show kvals and res for the initial k`s, right? And the other two show the arrays for the last set of k`s. But why do I have several columns in each of the inner arrays of res? Shouldn`t there be only an array of five vectors and not an array of five arrays with N+1 columns?
And how can I have a look at the results between the initial set of k`s and the last one? I want to write S1 and S2 for each set of k`s into a file, but I can`t find the right syntax to adress one of the inner arrays of res.
I hope you can help me once again!
Katharina
Katharina Hunger wrote:
Hi Stuart,
this really looks good. But I still have some questions:
The first two arrays at the bottom show kvals and res for the initial k`s, right? And the other two show the arrays for the last set of k`s. But why do I have several columns in each of the inner arrays of res? Shouldn`t there be only an array of five vectors and not an array of five arrays with N+1 columns?
And how can I have a look at the results between the initial set of k`s and the last one? I want to write S1 and S2 for each set of k`s into a file, but I can`t find the right syntax to adress one of the inner arrays of res.
I hope you can help me once again!
Katharina
Hi Katherina,
Unfortunately, work has got in the way of play 🙂
I'll have a look at it in a few hours time when I get back to my M2000 machine.
Stuart
That is absolutely fine for me. Have fun with your work 😉
Katharina Hunger wrote:
Hi Stuart,
this really looks good. But I still have some questions:
The first two arrays at the bottom show kvals and res for the initial k`s, right? And the other two show the arrays for the last set of k`s. But why do I have several columns in each of the inner arrays of res? Shouldn`t there be only an array of five vectors and not an array of five arrays with N+1 columns?
And how can I have a look at the results between the initial set of k`s and the last one? I want to write S1 and S2 for each set of k`s into a file, but I can`t find the right syntax to adress one of the inner arrays of res.
I hope you can help me once again!
Katharina
Oops! Silly me. You are quite right, Katharina, I forgot to remove the i1 loop. Updated version attached.
To get at the individual subvectors within a nested array, you have (effectively) 'nest' the indices.
Eg, to get S2 for the result index 5, you write
(res2)5 ... this looks OK in edit window but not in the main read page - I mean type res[2[5 - the second '[' automatically puts the parentheses around res[2
Unfortunately, whilst you can read a nested array using this syntax, you can't write to it at worksheet level.
Stuart
Ah, great! Now I can go on 🙂 Thank you once again!
Unfortunately, whilst you can read a nested array using this syntax, you can't write to it at worksheet level.
Does that mean I can`t build in a write-command in the loop?
Katharina Hunger wrote:
Ah, great! Now I can go on 🙂 Thank you once again!
Unfortunately, whilst you can read a nested array using this syntax, you can't write to it at worksheet level.
Does that mean I can`t build in a write-command in the loop?
By no means, Katherina. It just places a restriction on how you can set values in nested arrays.
See attached for an example of how to write your data for each kval ... all 162 files in this simple case. 🙂
Stuart
Ah, then I just missunderstood what you had written.
Since I don`t need to change single values in the arrays, but do some calculations with the vectors, everything is fine now. I will run my first test with actual data now 🙂
Thank you very much, Stuart!