Académique Documents
Professionnel Documents
Culture Documents
MATRIX OPERATIONS
define matrix a
define matrix b
Sum of matrix a and matrix b
subtract each element of matrix a by 1
product of matrix a & matrix b
element by element multiplication of matrix a & matrix b
division of matrix a & matrix b using left(/) division
division of matrix a & matrix b using right(\) division
transpose of sum of matrix a & matrix b
sum of transpose of matrix a & transpose of matrix b
inverse of matrix a
determinant of matrix a
Eigen vector & Eigen value of matrix a
define random matrix of 3 by 4
define zero matrix of 3 by 3 order
show the diagonal of matrix a as vector
show the upper triangular matrix of a
show the lower triangular matrix of a
define identity matrix of 3 by 3 order
a=[12 45 ; 25 70]
b=[ 34 6 ; 10 35]
a+b
a-1
a*b
a.*b
a/b
a\b
inv(a)
det(a)
eig(a)
rand(3,4)
zeros(3)
diag(a)
triu(a)
tril(a)
eye(3)
Q, 1.
Sol. 1.
Sol. 2
Given : velocity =0.25 m/s, Air flow rate= 65m3/s , Area = 50 m2, efficiency = 95%.
Sol.
Sol.
ODE 23
Q,6. Solve differential equation by ODE23.
Sol. function fv=funsys(t,y)
fv(1,1)=(2*y(1))+y(2)+(5*y(3))+exp((-2)*t);
fv(2,1)=(-3*y(1))-(2*y(2))-(8*y(3))+(2*exp(-2*t))-(cos(3*t));
fv(3,1)=(3*y(1))+(3*y(2))+(2*y(3))+(cos(3*t));
[t,Y]=ode23(@funsys,[0 2],[1 -1 0]);
plot(t,Y(:,1),'+',t,Y(:,2),'x',t,Y(:,3),'o')
= Y2
= 1000(1-Y1^2)Y2
Y1
function dy = vdp1000(t,y)
dy = zeros(2,1);
% a column vector
dy(1) = y(2);
dy(2) = 1000*(1 - y(1)^2)*y(2) - y(1);
[T,Y] = ode23 (@vdp1000,[0 3000],[2 0]);
plot(T,Y(:,1),'-o')
ODE45
Q,8 Solve
function dy=Dg(t,y)
dy = zeros(3,1); % a column vector
dy(1) = y(2) * y(3);
dy(2) = (-y(1)) * y(3);
dy(3) = (-0.51) * y(1) * y(2);
[T,Y] = ode45(@Dg,[0 12],[0 1 1]);
plot(T,Y(:,1),'-',T,Y(:,2),'-.',T,Y(:,3),'.')
grid on
xlabel('TIME')
ylabel('Function value')
title('ODE45').
Q,9. Solve:
function out1 = vdp1(t,y)
[t,y] = ode45('vdp1',[0 20],[2 0]);
out1 = [y(2); (1-y(1)^2)*y(2) - y(1)];
plot(t,y(:,1),'-',t,y(:,2),'-.')
xlabel('Time Interval')
ylabel('out')
title('vdp1')
grid on
Q,10. Find by Taylor series method, the value of y at x=0.1 and x= 0.2
dy/dx = 1- (2*x*y ) , y(0) = 0
Sol . function dydx=pro1(x,y)
y0=0;
t0=0;
tend=.2;
%solving using ode45
[t,y] = ode45(@pro1,[t0:.1:tend],y0);
dydx=1-2*x*y;
[t,y]
Q,12. Solve
function bvp3
solinit = bvpinit(linspace(0,1,5),[1 0]);
sol = bvp4c(@twoode,@twobc,solinit);
x = linspace(0,1);
y = deval(sol,x);
plot(x,y(1,:))
grid on
function dydx = twoode(x,y)
dydx = [ y(2)
1^(2)*y(1)*exp((20*0.1*(1-y(1)))/(1+0.1*(1-y(1)))) ];
function res = twobc(ya,yb)
res = [ ya(2)
yb(1) - 1];
Q,13. Solve
function BVP5
solinit = bvpinit(linspace(0,1,5),[0 1]);
sol = bvp4c( @twoode, @twobc, solinit);
x = linspace( 0,1);
y = deval(sol, x);
plot(y,x(1,:))
grid on
function dydx = twoode(x,y)
dydx = [ y(2)
(-p*(y(2))^2)/(1+p*y(1)) ];
function dydx = twobc(ya, yb)
dydx = [ ya(1)
yb(1)-1];