Dynamics/Linearization/Numerical Solutions/Single Variable with MATLAB

From Wikiversity
Jump to navigation Jump to search

Introduction[edit | edit source]

MATLAB Scripts can be simple and straightforward in linearizing and calculating a numerical solution to a non-linear expression of a single variable.

Using a MATLAB Script[edit | edit source]

The first two terms of the Taylor Series expansion, or linear approximation, result in the following:

Using MATLAB, there are a few options for performing linear approximations. Using this resource, we can run the following script to linear the following expression:

Code
clear all
close all

syms x a epsilon
f=(x.^2+sin(x)+1)
f_lin=subs(f,a)+subs(diff(f,x),a)*(x-a)
a=1;
f_lin_a_set=subs(f_lin);
simplify(subs(f_lin))

%An alternative technique for Tayor Series Expansion
%simplify(taylor(f,x,'ExpansionPoint',a,'order',2))

%Plotting f and the linearized solution

fplot([f f_lin_a_set],[0,3],'linewidth',3)
legend('f','Linearized f','Location','SouthEast')
xlabel('x','FontSize',12)
ylabel('f(x)','FontSize',12)
title('Linearization of f(x)=x^2+sin(x)+1 about x=1')

%Substitute  for 

x=a+epsilon;
simplify(subs(f_lin))

The figure shows a resulting depiction of the linearized function.

Linearization of x^2+sin(x)+1 using MATLAB

The linearized function near is the following:

Using MATLAB Simulink[edit | edit source]

We can substitute for in the expression:

Then, we create an appropriate block diagram as shown in the Figure.

Simulink block diagram for f(x)=x^2+sin(x)+1

We can then select the blocks between the ramp and the scope, right-click to create a subsystem block, select the new block, right-click an select "Linear Analysis", specify a point for linearization ( in this case), linearize, and look at the resulting linear analysis in terms of state-space representation.

For our example, we find the "Model Linearizer" gives a static gain of 2.54 for our subsystem block.

Individual or Group Activity[edit | edit source]

  • Write down your own individual non-linear expression.
  • Use Taylor or binomial series expansion to create an analytical expression for the linearized form of your expression at a specified location.
  • Calculate the slope at that specified location.
  • Write a MATLAB script to create a symbolic linearized expression at the specified location.
  • Use Simulink to calculate the slope at the specified location.
  • Create a presentation in Google Slides titled "Linearized Expression with a Single Variable" to share in 2 minutes with the class.

References[edit | edit source]