New to MATLAB, Need basic help

  • MATLAB
  • Thread starter SaRCaZZM
  • Start date
  • Tags
    Matlab
In summary, the conversation discusses the use of MATLAB's "solve" function to solve for the variable d in a long equation. The example provided in the conversation may have an error with the use of single quotes around the variable. The conversation also mentions using a FOR loop to generate and store values for a plotted equation, and using a WHILE loop to solve for a specific value with a specified increment. The conversation also reminds to include appropriate labels and clear and pause commands in the code.
  • #1
SaRCaZZM
1
0

Homework Statement


I need help solving for d, in the really long equation below. However, whenever I insert the following command (see below), I get 'is not a valid equation or expression', but I can't figure out why.


Homework Equations


((cot(104.789d))^2) + (((cot(104.789d))^2)*(1 + (-1.339*(10^-3)))*((sin(209.58d))^2))=-0.3939


The Attempt at a Solution


solve('((cot(104.789d))^2) + (((cot(104.789d))^2)*(1 + (-1.339*(10^-3)))*((sin(209.58d))^2))=-0.3939','d')
 
Physics news on Phys.org
  • #2
SaRCaZZM said:

Homework Statement


I need help solving for d, in the really long equation below. However, whenever I insert the following command (see below), I get 'is not a valid equation or expression', but I can't figure out why.


Homework Equations


((cot(104.789d))^2) + (((cot(104.789d))^2)*(1 + (-1.339*(10^-3)))*((sin(209.58d))^2))=-0.3939


The Attempt at a Solution


solve('((cot(104.789d))^2) + (((cot(104.789d))^2)*(1 + (-1.339*(10^-3)))*((sin(209.58d))^2))=-0.3939','d')

I suppose that when you write cot(104.789d) you really mean cot(104.789*d). The same with the arguments of the other trigonometric functions.
 
  • #3
I would recheck some examples of MATLAB's "solve" function. Your use of single quotes around the variable at the end of your expression, looks odd to me.
 
  • #4


1
Ask the user for inputs of the variables start, stop, inc and a. At runtime please enter values of 0, 30, 0.1 and 2, respectively. Plot the equation alt = sin(pi/4) + a•(t-5)2, where a is 2 and t varies from 0 to 30 with a step size of 0.1 in a figure 2. Use an appropriate FOR loop to generate and store the values of t and alt. Add a title, xlabel and ylabel to the plot. Remember to clear at the beginning and pause at the end of the code.


2
For the same “alt” equation above, use a WHILE loop to solve for the time t (starting from 0) at which alt crosses 600 but this time use inc of 0.01 instead of 0.1. Use the command sprintf to create an output message displaying the time at which this occurs (label your answer clearly). Remember to clear at the beginning and pause at the end of the code.
 
  • #5



I understand the frustration of trying to learn a new programming language like MATLAB. It can be overwhelming and confusing at first, but with practice and patience, you will become more comfortable with it.

In this particular case, the error you are receiving is likely due to the use of trigonometric functions in your equation. MATLAB requires the use of radians, not degrees, for trigonometric functions. So, when inputting the angle values, make sure to convert them to radians first. For example, 104.789 degrees would be 1.826 radians.

Additionally, it is good practice to break down complex equations into smaller, more manageable parts when using MATLAB. This can help identify any errors or issues more easily. So, you could try solving for each individual term (e.g. (cot(104.789d))^2) and then combining them in the final equation.

I hope this helps and good luck with your homework! Remember to always check your units and double check your equations for any potential errors. Science is all about attention to detail.
 

1. What is MATLAB and how do I get started?

MATLAB is a high-level programming language and interactive environment for numerical computation, visualization, and programming. To get started, you can download and install MATLAB from the official MathWorks website, and then refer to the documentation and tutorials provided to learn the basics of the language.

2. How do I create and manipulate arrays in MATLAB?

To create an array in MATLAB, you can use the square brackets notation with comma or space separators between elements. For example, A = [1, 2, 3; 4, 5, 6] creates a 2-by-3 matrix. To manipulate arrays, you can use built-in functions and operators such as size, reshape, and transpose.

3. What are the basic plotting functions in MATLAB?

MATLAB has a variety of powerful plotting functions, including plot, scatter, bar, histogram, and surf. These functions allow you to create 2D and 3D plots, customize the appearance of plots, and add labels, titles, and legends.

4. How can I import and export data in MATLAB?

To import data into MATLAB, you can use the load function to load data from a file, or the readtable function to read data from a spreadsheet. To export data, you can use the save function to save variables to a file, or the writetable function to write data to a spreadsheet.

5. What are some resources for learning more about MATLAB?

Aside from the official documentation and tutorials provided by MathWorks, there are many online resources available for learning more about MATLAB. These include YouTube tutorials, online courses, and forums where you can ask questions and get help from other users.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
980
Back
Top