lab question 1,2 and 3
Laplace transform and inverse laplace transform
syms t % symbolic varaibles
L=laplace(2*exp(-t)+sin(2*t))
pretty(L)
ilaplace(L)
L =
2/(s + 1) + 2/(s^2 + 4)
2 2
----- + ------
s + 1 2
s + 4
ans =
2*exp(-t) + sin(2*t)
lab question 4
partial-fraction
num=[2 5 3 6]
denum=[1 6 11 6]
[r,p,k]=residue(num,denum)
num =
2 5 3 6
denum =
1 6 11 6
r =
-6.0000
-4.0000
3.0000
p =
1
-3.0000
-2.0000
-1.0000
k =
Generate the polynomial:
x = linspace (0, 10, 100); % Generate linearly spaced vector 0-10 arası 100
nokta
y = 2*x.^2 + 7*x + 9;
% plotting the polynomial:
figure (1)
subplot(2,2,1)
grid on
ylabel('plot graphic')
plot(x,y) %generates a linear plot of the values of x (horizontal axis) and
y(vertical axis).
subplot(2,2,2)
semilogx (x,y); %generate a plot of the values of x and y using a linear
scale for x and a logarithmic scale for y.
grid on
ylabel('semilog graphic')
xlabel('time (s)')
title('Plotting')
subplot(2,2,3)
loglog (x,y); % generate both x and y logarthmic scale
grid on
ylabel('loglog graphic')
xlabel('time (s)')
title('Plotting')
subplot(2,2,4)
plot(x,y)
grid on
ylabel('plot graphic')
xlabel('time (s)')
title('Plotting')
legend('y')
%text(x,y,'y')
hold on
semilogx (y,x,'--b');
legend('semilog','y')
2
Polynomial Overview:
p=[1 0 -2 5]
r=roots(p) % kökleri verir
p2=poly(r) %kökleri verilen bir polinomun katsayılarını oluşturur.Köklerden
polinom üretir
polyval(p,5) %Polinomu sayıda hesaplar
eye(5)
zeros(5)
X=[2 4 5;-1 0 3;7 1 5]
Y=polyvalm(p,X)
% Convolution and Deconvolution
a=[1 2 3]
b=[4 5 6]
c=conv(a,b) % İki polinomu çarpar.
[q,r] = deconv(c,a) %Polinom bölmesi yapar. a bölen r kalan q bölüm
p=[1 0 -2 5]
polyder(p) % polinom türevi alır
p=polyder(a,b)
% transfer function and residue
num=[1 2 3]
denum=[4 5 6]
tf(a,b)
3
[r,p,k]=residue(num,denum)
[num,denum]=residue(r,p,k)
b = [-4 8]; a = [1 6 8]; [r,p,k] = residue(b,a)
[b2,a2] = residue(r,p,k)
p =
1 0 -2 5
r =
-2.0946 + 0.0000i
1.0473 + 1.1359i
1.0473 - 1.1359i
p2 =
1.0000 0.0000 -2.0000 5.0000
ans =
120
ans =
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
ans =
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
X =
2 4 5
-1 0 3
7 1 5
4
Y =
387 179 439
111 91 136
490 253 649
a =
1 2 3
b =
4 5 6
c =
4 13 28 27 18
q =
4 5 6
r =
0 0 0 0 0
p =
1 0 -2 5
ans =
3 0 -2
p =
16 39 56 27
num =
1 2 3
denum =
5
4 5 6
ans =
s^2 + 2 s + 3
---------------
4 s^2 + 5 s + 6
Continuous-time transfer function.
r =
0.0938 - 0.1224i
0.0938 + 0.1224i
p =
-0.6250 + 1.0533i
-0.6250 - 1.0533i
k =
0.2500
num =
0.2500 0.5000 0.7500
denum =
1.0000 1.2500 1.5000
r =
-12
8
p =
-4
-2
k =
[]
6
b2 =
-4 8
a2 =
1 6 8
Mathematical Modeling of Physical Systems ordinary differential equations (ODE).
v0=[0]; %iniail speed
[t,v] = ode45('cruise_speed',[0 200],v0);
plot(t,v);
grid on
title('cruise speed force exapmle')
xlabel('time');
%ylabel('dv/dt')
ylabel('$\dot{x}$','Interpreter','latex');
v0= 0; %(initial speed)
[t,v]=ode45('cruise_speed', [0 125],v0);
plot(t,v); grid on;
title('cruise speed time response to a constant traction force Fa(t) ')
% dsolve using
M=750;
B=30;
Fa=300;
dsolve('Dv = 300/750 - (30/750)*v', 'v(0)=0')
s=dsolve('Dy+5*y=4','y(0)=0','t')
t=0:0.1:5;
yt=eval(s);
plot(t,yt)
output = dsolve('D2y - 3*Dy + 2*y = -2*exp(3*t)','y(0)=0','Dy(0)=2')
t=0:0.1:1;
y=eval(output);
plot(t,y)
%new version
%diff(f, değişken, derece)
syms x
y = x^3 + 2*x
diff(y,x,2) %d^2y/dx
syms y(t)
eqn = diff(y,t,2) - 3*diff(y,t) + 2*y ==-2*exp(3*t);
Dy = diff(y,t);
7
cond = [y(0)==0, Dy(0)==2];
s = dsolve(eqn,cond)
Warning: Support for character vector or string inputs will be
removed in a future release. Instead, use syms to declare
variables and replace inputs such as dsolve('Dy = -3*y') with
syms y(t); dsolve(diff(y,t) == -3*y).
ans =
10 - 10*exp(-t/25)
Warning: Support for character vector or string inputs will be
removed in a future release. Instead, use syms to declare
variables and replace inputs such as dsolve('Dy = -3*y') with
syms y(t); dsolve(diff(y,t) == -3*y).
s =
4/5 - (4*exp(-5*t))/5
Warning: Support for character vector or string inputs will be
removed in a future release. Instead, use syms to declare
variables and replace inputs such as dsolve('Dy = -3*y') with
syms y(t); dsolve(diff(y,t) == -3*y).
output =
4*exp(2*t) - exp(3*t) - 3*exp(t)
y =
x^3 + 2*x
ans =
6*x
s =
4*exp(2*t) - exp(3*t) - 3*exp(t)
8
Mass-spirng-damper
X0=[0; 0]; %(initial speed and position)
[t,X]=ode45('mass_spring', [0 200],X0);
figure(1)
plot(t,X);
grid on;
title('Mass-spirng-damper time response to a constant traction force Fa(t) ')
legend('$x$','$v$','Interpreter','latex')
figure(2)
subplot(211)
plot(t,X(:,1))
xlabel('Time (s)')
ylabel('Position x(t)')
grid on
subplot(212)
plot(t,X(:,2))
xlabel('Time (s)')
ylabel('Velocity v(t)')
grid on
9
10
Published with MATLAB® R2024b
11