In this tutorial we will deal with analysis of functions, interpolation, curve fitting, integrals and differential equations. Firstly, we will need to use polynomials and therefore we have to be familiar with the representation of these. A general polynomial looks like: p(x)=anxn + an-1xn-1 +……….+ a1x + a0 and is represented by a vector in Matlab:
p=[ an an-1 ....... a1 a0 ]
Here we have a list of basic commands dealing with polynomials.
polyval(p,x): Calculates the value of polynomial p for different x. If x is a vector then the polynomial is evaluated for each element in the vector x.
poly(A): Gives a vector that represents the characteristic polynomial for the matrix A.
roots(p): Gives a vector with the zeros for the polynomial p(x)=0.
polyder(p): Gives a vector that represents the time-derivative of the polynomial p(x). The coefficients are sored in the vector p.
conv(p,q): Multiplies the polynomials p and q with each other. Returns a coefficient vector.
polyint(p): Integrates the polynomial p analytically and uses the constant of the integration c. The constant c is assigned to 0, if it is not explicitly given.
residue(p,q): Makes a partial fraction expansion of p(x)/q(x).
Read more »
Tags: analysis of functions, conv, curve fitting, differential equations, double integral, double integral in matlab, integrals, integrand2, interpolation, Interpolation of data sets, local maxima, local minima, matlab maxima, matlab minima, poly, polyder, polyint, polyval, residual, residue, roots, triple integral, triple integral in matlab, triplequad
Matlab Tutorials | admin, June 20, 2009 3:33 pm |
Comments (0)
In this Matlab tutorial we will deal with linear equations, the least square method, condition numbers over & under-determined equations.
Let’s start with an example.
Example 1
We have an equation system with three unknown variables and three equations. What will be the solution to the system below?
3w-2y+4z=8
5w+8y-6z=-5
9w-2y+7z=-17
Assume a matrix A containing the coefficients multiplied with x, y and z, and a vector with the numbers on the right-hand side of the equations. We can thus rewrite our equations as:
AX=b , where X contains the unknown (w, y and z), A and b are shown below.
b= A=
8 3 -2 4
-5 5 8 -6
-17 9 -2 7
How will we find the solution?
or
both gives a correct answer. The last method produces a Gaussian elimination if A is a quadratic matrix. In our case X becomes:
X=
-36.7778
71.2778
65.2222
This is no exact solution, only an approximation. Try also a specific command: Read more »
Tags: coefficients, complex conjugated, cubical functions, diagonal elements, differential equations, eigenvalues, eigenvectors, equation system, linear equations, linear system, linearly independent, Matlab Tutorials, quadratical functions, sparse matrices, tic, toc
Matlab Tutorials | admin, June 13, 2009 4:06 am |
Comments (0)
This tutorial covers data analysis and statistics using Matlab.
Histogram Charts in Matlab
The elements of a vector can be displayed with bars or histograms. To create a histogram you need to divide the elements in to classes and count how many elements that belongs to each class. Then present them as rectangular bars in a diagram. The height of the rectangle is equal to the number of elements in that class. Read the vector.

Matlab Histogram Example
- hist(x) Plots a histogram with 10 intervals (default) for the elements in vector x.
- hist(x,n) Plots a histogram with n intervals for the elements in vector x.
- hist(x,y) Plots a histogram with arbitrary intervals. These are given in vector x.
Introduce a histogram with 15 intervals for the vector x above. It is rather difficult to see how long the intervals are. Maybe its better to introduce a histogram with 6 intervals since we know the difference between the maximum and minimum value.
If we don’t know the dataset, we can define the intervals that we are interested to have in the histogram. Suppose we want the integer values between 0 and 10.
>> bar(x),grid
>> title('bar for vector x')

Histogram Bars with Grid in the Background
Stem Plot
To make this a bit more complete we show some other plotting possibilities. In Matlab we can also illustrate a discrete sequence (stem plot). This is done as:
Read more »
Tags: covariance, data analysis, data analysis using matlab, data analysis with matlab, grid on plots, histogram, mathlab tutorial, mathlab tutorials, matlab beginner, matlab codes, matlab courses, matlab data analysis, matlab examples, matlab exercises, matlab function examples, matlab functions, matlab histogram example, matlab samples, matlab statistics, matlab tutorial, mean, median, standart deviation, statistics, statistics examples matlab, stem plot, variance
Matlab Tutorials | admin, April 2, 2009 5:16 pm |
Comments (0)
The concept of variables is fundamental in all programming. In Matlab you introduce variables and assign values to them all by yourself. When you assign a value to a variable its previously assigned value will be overwritten. You can at any time find out the actual value of a variable simply by writing the variable name in the command window (without ;).
The class is decided by the assigned value.
>> a=1; % the class is double and the storage size is 8 bytes.
Open and check workspace.
In this laboratory we will investigate strings and conversions of strings among other things. A string is stored as a row vector, so that every element represents a character. Each character is accessible by the name of the vector and its indice.
Exercise 1: Assigning a variable to a string of characters
>> words='This is a string'
Press on enter to see the content of the variable words. Words has the size 1×16 elements. The class is char (character) and storage size 32 bytes.
>> words(2) % gives the second element in the variable words.
ans = h
>> words(2)='t' % replaces the second element in the vector with t.
Sooner or later we need some form of interactivity. For instance to get input from the user. To prompt the user for an input:
Read more »
Tags: mathlab tutorial, mathlab tutorials, matlab beginner, matlab codes, matlab courses, matlab examples, matlab exercises, matlab function evaluation, matlab function examples, matlab functions, matlab inline functions, matlab samples, matlab strings, matlab tutorial, matrices including different type of classes, strings in matlab, strings tutorial
Matlab Tutorials | admin, March 25, 2009 6:56 pm |
Comments (0)
Matrices in Matlab
In the previous tutorial we have used the concept vector. This is a special case of matrix. A two-dimensional matrix is nothing but a rectangular table with its elements ordered in rows and columns. A matrix mxn consists of m rows and n columns. In Matlab this can be written for a matrix A.
>> A= [ 1 2 3; 4 5 6 ] % semicolon separates rows.
This matrix A has 2 rows and 3 columns. The first row is: 1 2 3 and the second: 4 5 6 . For the columns we have the have following order: Column 1: 1,4 column 2: 2,5 and finally column 3: 3,6
Each entry in the matrix A is accessible by using the following indices:
A(row_index, column_index)
For instance try the following :
>> A(2,1)+A(2,3)+A(1,1) % adds three elements in A
or
The most common matrix in matlab is the two-dimensional one. Many of the commands in matlab are only for valid for such matrices. The arithmetic operators (+, -, *, / and ^) that we used in tutorial1 can also be applied for matrices, but we also have some others as well.
Exercise 1: Vectors in Matlab
Generate a vector x=[5, -4, 6 ] with three elements. In Matlab as:
or alternatively
>> x(1)=5; x(2)=-4; x(3)=6;
What is the answer of x(4) and x(0) ?
The indices in a vector starts from 1 and in this case ends with 3. Therefore to ask for x(4) and x(0) is pointless. Suppose we would have done differently creating the vector x. Read more »
Tags: combining matrices, inverse matrix, inverse of a matrix, mathlab tutorial, mathlab tutorials, matlab beginner, matlab codes, matlab courses, matlab examples, matlab exercises, matlab function examples, matlab functions, matlab matrices, matlab matrix operations, matlab samples, matlab tutorial, matrices in matlab, quadratic matrix, transpose, transpose matrix in matlab, zero matrix
Matlab Tutorials | admin, March 24, 2009 2:47 pm |
Comments (0)