Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X
Hello,
I would like to solve an equation containing vectors (the result is also a vector) using programming. I tried using the solve block as indicated in the attached file, but I don't obtain the expected results (see Case 2). The expected result should be equal to the "y" vector from Case 1 highlighted in grey.
Am I using the Solve block incorrectly? Is it possible to create a program for this situation (proffered solution).
I am using Mathcad Prime 8.
Thank you,
Otilia
Solved! Go to Solution.
One additional remark.
Because the equation uses R only squared, you may used this squared values the looked for.
Doing so seems to make the solve block more stable and quite independent from the guess value:
You (appear to) have a single equation and you want to solve for 4 variables....?
Then there is not one unique solution, but many (infinite) solutions are possible. Prime gives you one of them.
Your approach is similar to:
x=4, y=3 then x+y=7
Now if I know the sum is 7, determine x and y. One answer (of the many possible) is: x=0, y=7, because then (too) x+y=7.
See? That doesn't work.
But if you add another equation, e.g.: x-y=1, then you can solve x and y uniquely from their sum and difference.
x+y=7
x-y=1
add, to get:
x+x+y-y=7+1 => 2*x=8 => x=8/2=4, then with x+y=7 => y=7-x=7-4=3.
If you want to solve 4 variables to have a unique solution, you need 4 separate (independent) equations.
Success!
Luc
I want to solve the equation for one variable only, but the variable might be different according to the situation. Now is yy, but on a different case it could be the IntegWeight.
I think I understand now what you are saying, that yy is a vector of 4 variables. However, I tried the solution from the solve block in the Case 1 equation, the results is different.
Same problem, you have 4 values of IntegWeight, with indexes 1 through 4,
With your single equation that sums all parts, you can still solve only one variable uniquely.
Success!
Luc
To confirm that you get an endless number of solutions from your solve block, you can change the guess values to get different solutions or you can add constraints like these
You may even force the first three elements to specific values and use the solve block to calculate the missing fourth one:
So you will have to find out whats so special in the solution you are looking for. That way you may find more equations/Constraints to add to yor solve block.
I can add some constraints indeed, but unfortunately, this is a situation where if you don't know an input, you don't know the whole associated vector, there is no chance to know 3 out of 4 values.
Thank you Werner_E.
What if i want to write it as a program for solving it for "R"? "R" is a scalar (1 equation, 1 unknown). I'm asking because this will be part of a bigger calculation block, and the Solve block doesn't help in that case.
Can you upload the sheet with the failing solve block when you try to find R?
EDIT:
Guess I know what you are trying to achieve. Something like this:
But the solve block is quite sensible with respect to the guess value. Sometimes you may end up with a (tiny) imaginary part
and sometimes Primes algorithm is not able to find a solution
An additional constraint can help sometimes
But then - if you know that R is greater than 30 mm, why would you use a guess of 20 mm 😉
If you tried with a guess value 0, you probably ran into the "no solution found" error.
One additional remark.
Because the equation uses R only squared, you may used this squared values the looked for.
Doing so seems to make the solve block more stable and quite independent from the guess value:
@Otilia wrote:
I can add some constraints indeed, but unfortunately, this is a situation where if you don't know an input, you don't know the whole associated vector, there is no chance to know 3 out of 4 values.
Thats clear. I just wanted to demonstrate that with just one equation (and while vectors are involved its just one scalar equation) you can expect a unique solution only if you just solve for one variable.
As you can see after "check" the solve block returns a correct solution which fulfills the one equation given. Primes algorithm picked just one of an infinite number of possible valid solutions. Which one it picks can be changed by using different guess values or additional constraints.
If the solution Prime picks is not the solution you are looking for, you have to explain why its not a valid solution for your application. Doing so should bring up enough additional equations and constraints to force Prime to arrive at the wished for solution.
Actually, you can solve for the vector of values! Attached is a Prime 4 Express file that demonstrates that. Since the summation is of the combined variables it's possible to extract a coefficient for each of the four elements of the vector.
Solving for R is simple, but it wasn't part of the original problem.
Because the squared values are used, you do lose the sign of the original values.
The basic leap was getting rid of y and reverting to LCR: