cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

Solving an equation with vectors using programming

Otilia
6-Contributor

Solving an equation with vectors using programming

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

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:Werner_E)

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:

Werner_E_0-1667409234249.png

 

View solution in original post

11 REPLIES 11
LucMeekes
23-Emerald III
(To:Otilia)

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

Otilia
6-Contributor
(To:LucMeekes)

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.

Otilia
6-Contributor
(To:Otilia)

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. 

LucMeekes
23-Emerald III
(To:Otilia)

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

Werner_E
25-Diamond I
(To:Otilia)

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

Werner_E_0-1667395645634.png

You may even force the first three elements to specific values and use the solve block to calculate the missing fourth one:

Werner_E_1-1667395726072.png

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.

 

Otilia
6-Contributor
(To:Werner_E)

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.

Otilia
6-Contributor
(To:Otilia)

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.

Werner_E
25-Diamond I
(To:Otilia)

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:

Werner_E_0-1667407232739.png

But the solve block is quite sensible with respect to the guess value. Sometimes you may end up with a (tiny) imaginary part

Werner_E_1-1667407306438.png

and sometimes Primes algorithm is not able to find a solution

Werner_E_2-1667407352400.png

An additional constraint can help sometimes

Werner_E_3-1667407449485.png

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.

 

 

 

 

Werner_E
25-Diamond I
(To:Werner_E)

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:

Werner_E_0-1667409234249.png

 

Werner_E
25-Diamond I
(To:Otilia)


@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:

Fred_Kohlhepp_0-1667478863346.png

 

Announcements

Top Tags