Monday, February 4, 2013

Using Inline fuction

inline(expression, arg1, arg2 ...) constructs an inline function whose input arguments are specified by the stringsarg1, arg2, ...  Multicharacter symbol names may be used. This you can get from the matlab help.

Now.... how we can use them. I will divide it into different cases

  1. Function with one variable.
It can be used as
t = -4 : 0.01 : 4;
f = inline('(exp(t)+1)', 't');
This will define your function. Now if you want to plot it in the whole range of t, use
plot(t, f(t));
This will give you the following output (* click on the image to zoom in)
If you want to make the graph thicker use
plot(t,f(t),'linewidth', 2);
Test it with different values in place of 2. 

2. Plotting different functions on same base

If you want plot different function for different input values then try as follows
f = inline('(-1.5*t+1) .* ((t>-3)&(t<0)) + (3) .* (t == 0)+ (1.5*t+1) .* ((t>0)&(t<3))');
plot(t,f(t),'r','linewidth', 3);
grid on;
You will get the 

No comments:

Post a Comment