ezcontour (fun,domain)
ezcontour(f,[-3,3],49)
--------------------------------------- grid of 49 by 49
2. colormap([0 0 1])-------------- modify line plot color
3. ezplot(fun2,[xmin,xmax,ymin,ymax]) -------------- default domain -2 < x <2,
4. multiple plot ----------------Method 1 :
X = linspace(0,2*pi,50)';
Y = [cos(X), 0.5*sin(X)];
stem(Y)
for symbolic variable to plot after using dsolve
>>x = linspace(0,1,20);
>>z = eval(vectorize(y));
>>plot(x,z)
For Tabular form of display
>> table = [x y f y-f]
>> f = inline('cos(t)/(2*x - 2)','t','x')
Inline function:
f(t,x) = cos(t)/(2*x - 2)
We notice that f (0, 2) = 1/2, and
>> f(0,2)
ans =
0.5000
so it seems to be working correctly. The command ode45(f,[0,2*pi],3) 3 will plot the solution in
a figure window, with the computed points plotted as circles. Try it yourself. If you want to save the
computed data, execute [t,x] = ode45(f,[0,2*pi],3);.
x = -3:3;
y = [-1 -1 -1 0 1 1 1];
t = -3:.01:3;
p = pchip(x,y,t);
s = spline(x,y,t);
plot(x,y,'o',t,p,'-',t,s,'-.')
legend('data','pchip','spline',4)
x = a:b;
y = cos(x);
pp = spline(x,y);
int2 = integral(@(x)ppval(pp,x),a,b)
syms x
y = solve(x^2 - 2,x)
y =
2^(1/2)
-2^(1/2)
Approximate the solutions with floating-point numbers:
vpa(y(1))
vpa(y(2))
ans =
1.4142135623730950488016887242097
ans =
-1.4142135623730950488016887242097
JACOBIAN And Gradient
subs(gradient(-2*x-5*y+4*x^2-5*x*y+3*y^2, [x y]),[x y],[0.1 0.5])
Examples
Jacobian of a Vector Function
The Jacobian of a vector function is a matrix of the partial derivatives of that function.
Compute the Jacobian matrix of [x*y*z,
y^2, x + z] with respect to [x, y, z].
syms x y z
jacobian([x*y*z, y^2, x + z], [x, y, z])
ans =
[ y*z, x*z, x*y]
[
0, 2*y,
0]
1,
1]
0,
Now, compute the Jacobian of [x*y*z,
y^2, x + z] with respect to [x; y; z].
jacobian([x*y*z, y^2, x + z], [x; y; z])
Jacobian of a Scalar Function
The Jacobian of a scalar function is the transpose of its gradient.
Compute the Jacobian of 2*x
+ 3*y + 4*z with respect to [x, y, z].
syms x y z
jacobian(2*x + 3*y + 4*z, [x, y, z])
ans =
[ 2, 3, 4]
Now, compute the gradient of the same expression.
gradient(2*x + 3*y + 4*z, [x, y, z])
ans =
2
3
4
Jacobian with Respect to a Scalar
The Jacobian of a function with respect to a scalar is the first derivative of that function. For a vector function, the
Jacobian with respect to a scalar is a vector of the first derivatives.
Compute the Jacobian of [x^2*y,
x*sin(y)] with respect to x.
syms x y
jacobian([x^2*y, x*sin(y)], x)
ans =
2*x*y
sin(y)
Now, compute the derivatives.
diff([x^2*y, x*sin(y)], x)
ans =
[ 2*x*y, sin(y)]
[V,D]=eig(K,M)
TT=@(x) 73.4523*exp(0.1*x)-53.4523*exp(-0.1*x)+20;