Matlab help. invalid target for assignment trying to solve

In summary, the conversation involves a person trying to solve for beta using MATLAB but is having trouble. The code snippet provided is attempting to calculate a value of beta within a specific range. However, it is mentioned that MATLAB may not be the best tool for this type of problem.
  • #1
tigertan
25
0

Homework Statement



hey there,
i'm trying to solve for beta which I tought i'd easily be able to figure out using MATLAB (i'm not the most proficient MATLAB user) but i can't get it to work..

Homework Equations





The Attempt at a Solution



My code is as follows:

clear all;
close all;
clc;

Code:
m = 8;
a = 0.3;
l = 0.5;
g = 9.81;
I2y = 2;
I2z = 0.2;
omega = 7;

syms b

omega^2=(m*g*l*tan(b))/((sin(b)*(m*l^2+I2y-I2z)+m*a*l)

I would like to solve for beta within the range of -pi to pi
 
Physics news on Phys.org
  • #2
You are going to have to be a little more specific for us slow folks.

What is beta? How does the code snippet you provided figure in the solution of beta?

Please follow the Homework template so we don't have to play these guessing games.
 
  • #3
sorry, beta is b
i would like to solve the last equation. I would like to solve for 'b'. It is the only symbolic as the constants for the other letters are defined above
 
  • #4
I'm not a Matlab expert, but I don't think it's used as a computer algebra system, which is what you require to isolate beta. Now, if you just want to calculate a value of beta which satisfies the equation you have, knwing the values of the other variables, you can use Matlab to do this, but it requires extra programming. You can't just toss an arbitrary expression at Matlab and have it provide a solution.
 
  • #5
. However, when I try to assign the value of beta using the 'syms' function, I get an error saying "invalid target for assignment". I'm not sure what I'm doing wrong. Any help would be greatly appreciated.



Hi there,

It looks like you may have a syntax error in your code. The 'syms' function is used to declare symbolic variables in MATLAB, but you are trying to assign a value to the variable 'b' using the '=' sign. Instead, you should use the 'solve' function to solve for the value of beta. Your code should look something like this:

clear all;
close all;
clc;

m = 8;
a = 0.3;
l = 0.5;
g = 9.81;
I2y = 2;
I2z = 0.2;
omega = 7;

syms b

eqn = omega^2 == (m*g*l*tan(b))/((sin(b)*(m*l^2+I2y-I2z)+m*a*l));

sol = solve(eqn, b);

disp(sol)

This should give you the solutions for beta within the range of -pi to pi. I hope this helps! If you continue to have trouble, I recommend checking out some MATLAB tutorials or reaching out to your instructor or classmates for assistance. Good luck with your assignment!
 

Related to Matlab help. invalid target for assignment trying to solve

1. What does the error "invalid target for assignment" mean in Matlab?

The error "invalid target for assignment" in Matlab means that the target variable on the left side of the assignment operator (=) does not exist or is not properly defined. This could be due to a typo in the variable name or because the variable has not been initialized before trying to assign a value to it.

2. How can I solve the "invalid target for assignment" error in Matlab?

To solve the "invalid target for assignment" error in Matlab, you need to make sure that the target variable is properly defined and initialized before trying to assign a value to it. Check for any typos in the variable name and make sure the variable name is not a reserved keyword in Matlab. You can also try using the "exist" function to check if the variable exists before assigning a value to it.

3. Why am I getting the "invalid target for assignment" error when solving a system of equations in Matlab?

The "invalid target for assignment" error may occur when solving a system of equations in Matlab if the target variables for the equations are not properly defined or initialized. Make sure that all the variables in the system of equations are properly defined and that the number of equations matches the number of variables.

4. Can I use the "disp" function to solve the "invalid target for assignment" error in Matlab?

No, the "disp" function will not solve the "invalid target for assignment" error in Matlab. The "disp" function is used to display the value of a variable, but it will not solve any errors in your code. You will need to properly define and initialize your target variable in order to solve this error.

5. How can I prevent the "invalid target for assignment" error in Matlab?

To prevent the "invalid target for assignment" error in Matlab, make sure to carefully check and double-check your code for any typos or incorrect variable names. It is also a good practice to initialize all your variables before using them in assignments. You can also use the "exist" function to check if a variable exists before trying to assign a value to it.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
Back
Top