Skip to main content
1-Visitor
November 2, 2022
Solved

Solving an equation with vectors using programming

  • November 2, 2022
  • 2 replies
  • 3404 views

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

Best answer by 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

 

2 replies

23-Emerald IV
November 2, 2022

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

Otilia1-VisitorAuthor
1-Visitor
November 2, 2022

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.

Otilia1-VisitorAuthor
1-Visitor
November 2, 2022

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. 

25-Diamond I
November 2, 2022

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.

 

Otilia1-VisitorAuthor
1-Visitor
November 2, 2022

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.

Otilia1-VisitorAuthor
1-Visitor
November 2, 2022

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.