How Do I Perform Variable Calculations and Write Code in MATLAB?

In summary, you can create a new file in MATLAB and write your code there, or you can use MATLAB's help files and commands.
  • #1
atlbraves49
81
0
I need some help with some basic MATLAB questions.

1) When writing a MATLAB code, do I create a blank new M-file, and write it there?

2) I need the program to calculate values for an equation, as I vary two variable within the equation. I'm unsure how to do this (for example, how do I define the variables, etc)

For example, say the equation is y = x^(-0.5) +z^(ln(x));

I want the program to give me values for y when i input different values for x and z. How is this accomplished?

If anyone can point me to good MATLAB tutorials that go into this kind of detail, I'd appreciate it. I've looked, including MATLABs help, and haven't found anything regarding equations and variables, etc.

Lastly, how do you comment in MATLAB?
 
Physics news on Phys.org
  • #2
There are hundreds of web pages out there that give the basics for how to do these things in Matlab. A quick Google search will get you going.
 
  • #3
And the Help-files that come with Matlab are actually very good...
 
  • #4
atlbraves49 said:
I've looked, including MATLABs help, and haven't found anything regarding equations and variables, etc.



Can anyone provide some actual help regarding these questions?
 
  • #5
atlbraves49 said:
Can anyone provide some actual help regarding these questions?

Regarding this specific question, you're probably looking for an inline function:
http://en.wikibooks.org/wiki/MATLAB_Programming/Portable_Functions

That's the serial way of doing things. However, you can often perform operations on entire vectors. If you wanted to calculate, say, sin(x) between 0 and 2pi, in increments of 1/200*pi (and then plot the result), you'd do the following:

>> x=0:1/200*pi:2*pi %The colon format goes start:increment:end
>> y=sin(x) %This will generate a vector of y values for a bunch of x's
>> plot(x,y)

Additionally, perhaps start here:
http://en.wikibooks.org/wiki/MATLAB_Programming

Or here:
http://www.mathworks.com/access/helpdesk/help/techdoc/learn_matlab/bqr_2pl.html

But if you need a quick reference for a command within MATLAB, just type help COMMAND, for instance, getting help about the identity matrix creation function:
>> help eye
 

Related to How Do I Perform Variable Calculations and Write Code in MATLAB?

1. What is MATLAB and what is it used for?

MATLAB is a high-level programming language and interactive environment that is commonly used for technical computing and data visualization. It allows users to perform complex numerical calculations, create and manipulate data plots, and develop algorithms for various applications.

2. How do I get started with using MATLAB?

To get started with using MATLAB, you will need to download and install the software on your computer. Once installed, you can launch the program and start exploring its features and functions. There are also many online tutorials and resources available to help beginners learn the basics of MATLAB.

3. What are some basic commands and functions in MATLAB?

Some basic commands and functions in MATLAB include arithmetic operations, data manipulation, plotting, and creating user-defined functions. These can be used to perform various tasks such as data analysis, simulation, and modeling.

4. Can I use MATLAB for data analysis and visualization?

Yes, MATLAB is commonly used for data analysis and visualization. It has built-in functions and tools that allow users to import, clean, and analyze large datasets, as well as create visually appealing plots and graphs to represent the results.

5. Is MATLAB suitable for all types of scientific research?

While MATLAB is a powerful tool for many types of scientific research, it may not be the best option for every field. It is commonly used in fields such as engineering, mathematics, and physics, but may not be as suitable for research in social sciences or humanities.

Similar threads

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