Nothing Special   »   [go: up one dir, main page]

5 - MatLab Tutorial

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

TUTORIAL

1. A simple electric circuit consisting of a resistor, a capacitor, and an inductor is given in


below figure.

The charge on the capacitor q(t) as a function of time can be computed as

1 𝑅 2
𝑞 = 𝑞0 𝑒 −𝑅𝑡/(2𝐿)
𝑐𝑜𝑠 [ √ − ( ) 𝑡]
𝐿𝐶 2𝐿
where t = time, q0 = the initial charge, R = the resistance, L = inductance, and C =
capacitance. Use MATLAB to generate a plot of this function from t = 0 to 0.8, given that
q0 = 10, R = 60, L = 9, and C = 0.00005. (You can take the increment as 0.1 for time). Axis
labels should be bold and 12 points. Title should be bold and 14 points. Also there should
be a legend on the plot.

%% T(1)
% givens
q0 = 10;
R = 60;
L = 9;
C = 0.00005;

% time = 0 to 0.8; increment can be 0.1


t = 0:0.1:0.8;

% charge within time is


q = q0*exp((-R.*t)/2*L).*cos(sqrt((1/L*C)-(((R/2*L)^2).*t)));

%% plotting
h = plot(t,q, 'LineWidth', 1.5, 'Color', 'c', 'Marker', 'h', 'MarkerSize', 12,
'MarkerFaceColor', 'k', 'MarkerEdgeColor', 'c');
title('Charge Variations within Time', 'FontSize', 14, 'FontWeight', 'bold');
xlabel('Time', 'FontSize', 12, 'FontWeight', 'bold');
ylabel('Charge', 'FontSize', 12, 'FontWeight', 'bold');
legend('q');

2. The standard normal probability density function is a bell-shaped curve that can be
represented as

1 −𝑧 2⁄
𝑓(𝑧) = 𝑒 2
√2𝜋

Use MATLAB to generate a plot of this function from z = -5 to 5. Label the ordinate as
frequency and the abscissa as z.

%% T(2)
% givens
z = -5:1:5;
f = (1/sqrt(2*pi))*exp(-z.^2/2);
plot(z,f);
xlabel('z');
ylabel('frequency');
3*. The trajectory of an object can be modeled as

𝑔 2
𝑦 = (𝑡𝑎𝑛𝜃0 )𝑥 − 𝑥 + 𝑦0
2𝑣02 𝑐𝑜𝑠 2 𝜃0

where y = height (m), θ0 = initial angle (radians), x = horizontal distance (m), g =


gravitational acceleration (9.81 m/s2), v0 = initial velocity (m/s), and y0 = initial height.
Use MATLAB to find the trajectories for y0 = 0 and v0 = 28 m/s for initial angles ranging
from 15 to 75o in increments of 15o. Employ a range of horizontal distances from x = 0 to
80 m in increments of 5 m. The results should be assembled in an array where the first
dimension (rows) corresponds to the distances, and the second dimension (columns)
corresponds to the different initial angles. Use this matrix to generate a single plot of the
heights versus horizontal distances for each of the initial angles. Employ a legend to
distinguish among the different cases, and scale the plot so that the minimum height is
zero using the axis command.

You might also like