Solving for variables in matlab

In summary, to find the value of Sz for the given vectors S, P, and Q, the code should use the condition for perpendicularity and solve for Sz using the MATLAB solve() function. The solution for Sz is -12.
  • #1
Dell
590
0
i need to make a code that can sole the following, finding the value of Sz
given the following vectors

S=[ -6, -6, -Sz]
P=[ 0 -6 -3]
Q=[ 5 4 -9]

i need to make a code that can find Sz so that
a)S [tex]\bot[/tex]P
b)S[tex]\bot[/tex]Q
c)S[tex]\bot[/tex](PxQ)
d)(SxP)[tex]\bot[/tex]Q

i have managed to make MATLAB give me a condition for [tex]\bot[/tex], for example, what i set up is:

>>Sz=sym('Sz');
>>S=[ -6, -6, -Sz];
>>P=[ 0 -6 -3];
>>Q=[ 5 4 -9];
>>answer=S*P'


matlab returns
answer =

36+3*Sz


and i know that answer=0, therefore Sz=-12, but how do i get MATLAB to tell me that Sz=-12??
 
Physics news on Phys.org
  • #2
build a string that is

'36+3*Sz = 0'

teh num2sr() command may help if the answer is not 0 all the timethen its just:
>> solve('36+3*Sz = 0')
 
Last edited:
  • #3


To solve for Sz in MATLAB, you can use the "solve" function. This function allows you to solve for a variable in an equation or a system of equations. In this case, you can use the "solve" function to solve for Sz in the equation "answer = 0".

The syntax for using the "solve" function is as follows:

solve(equation, variable)

So in your case, you can use the following code:

>> Sz = sym('Sz');
>> S = [-6, -6, -Sz];
>> P = [0, -6, -3];
>> Q = [5, 4, -9];
>> answer = S*P';
>> solve(answer == 0, Sz)

This will return the solution for Sz, which in this case is -12.

You can also use the "solve" function to solve for multiple variables at once. For example, if you wanted to solve for both Sz and P in the equation "answer = 0", you can use the following code:

>> solve(answer == 0, [Sz, P])

This will return the values for both Sz and P that satisfy the equation.

Additionally, you can use the "solve" function to solve for a variable in a system of equations. For example, to solve for Sz in the system of equations "S \bot P" and "S \bot Q", you can use the following code:

>> Sz = sym('Sz');
>> S = [-6, -6, -Sz];
>> P = [0, -6, -3];
>> Q = [5, 4, -9];
>> solve(S*P' == 0, S*Q' == 0, Sz)

This will return the value of Sz that satisfies both equations.

In summary, to solve for variables in MATLAB, you can use the "solve" function and provide the equation or system of equations you want to solve, along with the variable you are solving for.
 

1. How do I define and solve for variables in matlab?

To define a variable in matlab, use the syntax variable_name = value. To solve for a variable, use the solve function, followed by the equation and the variable you want to solve for. For example, solve('2*x + 5 = 10', 'x') will solve for the variable x in the equation 2*x + 5 = 10.

2. Can I solve for multiple variables at once in matlab?

Yes, you can solve for multiple variables at once in matlab by using the solve function with a system of equations. For example, solve('x + y = 5', 'x + 2*y = 10', 'x', 'y') will solve for the variables x and y in the system of equations x + y = 5 and x + 2*y = 10.

3. What if I have an equation with both numbers and variables in matlab?

If you have an equation with both numbers and variables, you can still use the solve function in matlab. Just make sure to use the correct syntax for defining variables and include them in the equation as needed. For example, solve('2*x + y = 10', 'x', 'y') will solve for the variables x and y in the equation 2*x + y = 10.

4. Can I use matlab to solve equations with exponents and logarithms?

Yes, matlab has built-in functions for solving equations with exponents and logarithms. For example, you can use the power function for exponents and the log function for logarithms. You can also use the exp function for solving equations with the exponential constant e.

5. Is there a way to check if my solution is correct in matlab?

Yes, you can use the subs function in matlab to substitute the solved values into the original equation and check if the result is equal to the other side of the equation. For example, if your equation is x + 2 = 5 and you have solved for x as 3, you can use subs(x + 2, 3) to check if the result is 5.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
809
  • Engineering and Comp Sci Homework Help
Replies
9
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
10
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
882
  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
32
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
10
Views
1K
Back
Top