MATLAB Exercises and Solutions Guide
MATLAB Exercises and Solutions Guide
MATLAB can be used to simulate the free response of an RC circuit by setting the initial conditions and using a numerical method such as the ODE solver. Given an RC constant of 0.1 seconds and an initial capacitor voltage y(0) = 2V, set up the differential equation RC*dy/dt = -y with applied voltage v = 0. Use the MATLAB ode45 function to numerically solve this ODE over a specified time span to observe the voltage response .
To perform convolution on discrete sequences in MATLAB, define the discrete sequences using vectors. Use the conv() function to compute their convolution, which mathematically combines the two sequences to generate a convolved signal. This operation is foundational in digital signal processing for assessing the output response of linear time-invariant systems given an input sequence .
In MATLAB, write a function that takes a temperature and unit (Celsius or Fahrenheit) as inputs. Define the conversion formulas: °F = °C * 9/5 + 32 for Celsius to Fahrenheit and °C = (°F - 32) * 5/9 for Fahrenheit to Celsius. Implement the switch-case structure to determine which conversion to apply. This program enables bi-directional temperature conversion by utilizing MATLAB's robust processing capabilities .
In MATLAB, standard signals can be constructed using functions like step(), ramp(), impulse(), and sin(). For visualization, create time vectors, use these functions to generate signal data, and then plot them using MATLAB plotting functions such as plot(). To enhance the visualization, use the hold on command to overlay multiple signals on a single graph. The command subplot() can also be employed to create a collective representation of different signals in a single figure window .
Develop MATLAB functions to solve differentiation and integration problems. Use diff() for numerical differentiation and int() or trapz() for symbolic or numerical integration, respectively. Validate results by comparing them against analytical solutions, plotting functions and derivatives, or evaluating integrals over known bounds. This approach allows comprehensive solution checking and increases understanding of underlying mathematical principles .
To compute statistical measures in MATLAB, first generate a data set using constructs like arrays or matrices. Then, use the functions mean(data) for mean, std(data) for standard deviation, and var(data) for variance. Additionally, histogram(data) can be used for distribution visualization, and rms(data) for the root mean square value. MATLAB's built-in functions make it efficient to extract these statistical properties from large data sets .
In MATLAB, to calculate and plot the velocity and position of a mass-spring-damping system, define system parameters m = 2, c = 3, k = 7, and external force u = 35. Set up the second-order ODE m*y'' + c*y' + k*y = u. Use initial conditions y(0) = 2, y'(0) = -3. Solve using the ode45 function, which numerically integrates the system's differential equation from the initial conditions over a defined time span. Use plot commands to visualize both y(t) and y'(t).
To add and plot transfer functions in MATLAB, define the transfer functions Y1 = 50/(s² + 5s + 30) and Y2 = (2s² + 3s)/(4s² + 3s) using tf syntax. Use tfaddition = Y1 + Y2 to add them. Apply the bode(tfaddition) or step(tfaddition) commands to plot frequency response or step response. MATLAB’s control systems toolkit simplifies operations on transfer functions, enabling easy addition and visualization .
To calculate the determinant of a matrix resulting from the sum of two 4x4 matrices in MATLAB, first construct the matrices A and B. Use the command sum(A) and sum(B) to calculate the sum of their rows and columns, respectively. Then, use C = A + B to form the resulting matrix. Finally, use det(C) to find the determinant of matrix C .
To solve the equation of motion for a pendulum in MATLAB, define the pendulum's parameters: L = 1m, g = 9.8m/s², θ(0) = 0.05 radian. Set up the differential equation θ'' + (g/L)sin(θ) = 0. Discretize the time span and use ode45 or similar ODE solvers to compute θ(t) over time. Specify initial conditions in the solver call. MATLAB will solve the nonlinear ODE using numerical methods and allow you to plot θ over time for analysis .