mahumadac
Structural
- Jul 1, 2015
- 3
Hi there,
Looking up on the internet I found nothing about using vector variables in a MathCad Given-Find block, or using them inside a loop. Trying and trying I found a way.
This will be useful for those who want to solve several times the same equation using different parameters values and different guess values for the solve block, without having to use a Given solve block for each value at a time, but solving for all at once instead. It goes like this:
1. Define guess values variable as a vector the length of the number of equations you wish to solve
2. Start the Given block typing Given
3. Below the Given statement, type the equations you wish to solve as you would do for a single sized variable, but use the subindex indicator "[" next to each vector parameter or vector variable and put an undefined variable as subindex.
4. Define a function containing the Find funtion inside, with 2 parameters: the variable you wish to solve from the equation defined in step 3 and the variable in the subindexes I mentioned in step 3. This function should go like this: solveFunction(x,subindex)=Find(x)
5. Use a for loop or while loop to get all the solutions. Inside the loop, you must assign to each cell of a vector the "solveFunction" function with the "x" variable you want to solve (which is already defined as the guess values in step 1) and the loop counter variable as the "subindex" parameter. You actually will need to assign to each cell a subindex of the solverFunction (equals to the counter variable), since the solverFunction will return a vector the size of "x", with the current solution in the current loop counter number and all the oter values as the guess values assigned to "x" previously.
I hope this is useful. it was for me. Good luck!
Looking up on the internet I found nothing about using vector variables in a MathCad Given-Find block, or using them inside a loop. Trying and trying I found a way.
This will be useful for those who want to solve several times the same equation using different parameters values and different guess values for the solve block, without having to use a Given solve block for each value at a time, but solving for all at once instead. It goes like this:
1. Define guess values variable as a vector the length of the number of equations you wish to solve
2. Start the Given block typing Given
3. Below the Given statement, type the equations you wish to solve as you would do for a single sized variable, but use the subindex indicator "[" next to each vector parameter or vector variable and put an undefined variable as subindex.
4. Define a function containing the Find funtion inside, with 2 parameters: the variable you wish to solve from the equation defined in step 3 and the variable in the subindexes I mentioned in step 3. This function should go like this: solveFunction(x,subindex)=Find(x)
5. Use a for loop or while loop to get all the solutions. Inside the loop, you must assign to each cell of a vector the "solveFunction" function with the "x" variable you want to solve (which is already defined as the guess values in step 1) and the loop counter variable as the "subindex" parameter. You actually will need to assign to each cell a subindex of the solverFunction (equals to the counter variable), since the solverFunction will return a vector the size of "x", with the current solution in the current loop counter number and all the oter values as the guess values assigned to "x" previously.
I hope this is useful. it was for me. Good luck!