Integration - MATLAB & Simulink (2024)

Integration

If f is a symbolic expression, then

int(f)

attempts to find another symbolic expression, F, so that diff(F)=f. That is, int(f) returns the indefinite integral or antiderivative of f (provided one exists in closed form). Similar to differentiation,

int(f,v)

uses the symbolic object v as the variable of integration, rather than the variable determined by symvar. See how int works by looking at this table.

Mathematical Operation

MATLAB® Command

xndx={log(x)ifn=1xn+1n+1otherwise.

int(x^n) or int(x^n,x)

0π/2sin(2x)dx=1

int(sin(2*x), 0, pi/2) or int(sin(2*x), x, 0, pi/2)

g = cos(at + b)

g(t)dt=sin(at+b)/a

g = cos(a*t + b) int(g) or int(g, t)

J1(z)dz=J0(z)

int(besselj(1, z)) or int(besselj(1, z), z)

In contrast to differentiation, symbolic integration is a more complicated task. A number of difficulties can arise in computing the integral:

  • The antiderivative, F, may not exist in closed form.

  • The antiderivative may define an unfamiliar function.

  • The antiderivative may exist, but the software can't find it.

  • The software could find the antiderivative on a larger computer, but runs out of time or memory on the available machine.

Nevertheless, in many cases, MATLAB can perform symbolic integration successfully. For example, create the symbolic variables

syms a b theta x y n u z

The following table illustrates integration of expressions containing those variables.

f

int(f)

syms x nf = x^n;
int(f)
ans =piecewise(n == -1, log(x), n ~= -1,... x^(n + 1)/(n + 1))
syms yf = y^(-1);
int(f)
ans =log(y)
syms x nf = n^x;
int(f)
ans =n^x/log(n)
syms a b thetaf = sin(a*theta+b);
int(f)
ans =-cos(b + a*theta)/a
syms uf = 1/(1+u^2);
int(f)
ans =atan(u)
syms xf = exp(-x^2);
int(f)
ans =(pi^(1/2)*erf(x))/2

In the last example, exp(-x^2), there is no formula for the integral involving standard calculus expressions, such as trigonometric and exponential functions. In this case, MATLAB returns an answer in terms of the error function erf.

If MATLAB is unable to find an answer to the integral of a function f, it just returns int(f).

Definite integration is also possible.

Definite Integral

Command

abf(x)dx

int(f, a, b)

abf(v)dv

int(f, v, a, b)

Here are some additional examples.

f

a, b

int(f, a, b)

syms xf = x^7;
a = 0;b = 1;
int(f, a, b)
ans =1/8
syms xf = 1/x;
a = 1;b = 2;
int(f, a, b)
ans =log(2)
syms xf = log(x)*sqrt(x);
a = 0;b = 1;
int(f, a, b)
ans =-4/9
syms xf = exp(-x^2);
a = 0;b = inf;
int(f, a, b)
ans =pi^(1/2)/2
syms zf = besselj(1,z)^2;
a = 0;b = 1;
int(f, a, b)
ans =hypergeom([3/2, 3/2],... [2, 5/2, 3], -1)/12

For the Bessel function (besselj) example, it is possible to compute a numerical approximation to the value of the integral, using the double function. The commands

syms za = int(besselj(1,z)^2,0,1)

return

a =hypergeom([3/2, 3/2], [2, 5/2, 3], -1)/12

and the command

a = double(a)

returns

a = 0.0717

Integration with Real Parameters

One of the subtleties involved in symbolic integration is the “value” of various parameters. For example, if a is any positive real number, the expression

eax2

is the positive, bell shaped curve that tends to 0 as x tends to ±∞. You can create an example of this curve, for a=1/2.

syms xa = sym(1/2);f = exp(-a*x^2);fplot(f)

Integration- MATLAB & Simulink (1)

However, if you try to calculate the integral

eax2dx

without assigning a value to a, MATLAB assumes that a represents a complex number, and therefore returns a piecewise answer that depends on the argument of a. If you are only interested in the case when a is a positive real number, use assume to set an assumption on a:

syms aassume(a > 0)

Now you can calculate the preceding integral using the commands

syms xf = exp(-a*x^2);int(f, x, -inf, inf)

This returns

Integration with Complex Parameters

To calculate the integral

1a2+x2dx

for complex values of a, enter

syms a x f = 1/(a^2 + x^2);F = int(f, x, -inf, inf)

Use syms to clear all the assumptions on variables. For more information about symbolic variables and assumptions on them, see Use Assumptions on Symbolic Variables.

The preceding commands produce the complex output

F = (pi*signIm(1i/a))/a

The function signIm is defined as:

signIm(z)={1ifIm(z)>0,orIm(z)=0andRe(z)<00ifz=0-1otherwise.

Integration- MATLAB & Simulink (2)

To evaluate F at a = 1 + i, enter

g = subs(F, 1 + i)
g = pi*(1/2 - 1i/2)
double(g)
ans = 1.5708 - 1.5708i

High-Precision Numerical Integration Using Variable-Precision Arithmetic

High-precision numerical integration is implemented in the vpaintegral function of the Symbolic Math Toolbox™. vpaintegral uses variable-precision arithmetic in contrast to the MATLAB integral function, which uses double-precision arithmetic.

Integrate besseli(5,25*u).*exp(-u*25) by using both integral and vpaintegral. The integral function returns NaN and issues a warning while vpaintegral returns the correct result.

syms uf = besseli(5,25*x).*exp(-x*25);fun = @(u)besseli(5,25*u).*exp(-u*25);usingIntegral = integral(fun, 0, 30)usingVpaintegral = vpaintegral(f, 0, 30)
Warning: Infinite or Not-a-Number value encountered. usingIntegral = NaNusingVpaintegral =0.688424

For more information, see vpaintegral.

See Also

int | diff | vpaintegral

External Websites

  • Calculus Integrals (MathWorks Teaching Resources)

MATLAB Command

You clicked a link that corresponds to this MATLAB command:

 

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Integration- MATLAB & Simulink (3)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本 (日本語)
  • 한국 (한국어)

Contact your local office

Integration
- MATLAB & Simulink (2024)

FAQs

How to use MATLAB with Simulink? ›

Create a Simulink Model
  1. In the MATLAB® Home tab, click the Simulink button.
  2. Click Blank Model, and then Create Model. ...
  3. On the Simulation tab, click Library Browser.
  4. In the Library Browser: ...
  5. Make the following block-to-block connections: ...
  6. Double-click the Transfer Fcn block. ...
  7. Double-click the Signal Generator block.

What is MATLAB and Simulink? ›

Simulink is a MATLAB-based graphical programming environment for modeling, simulating and analyzing multidomain dynamical systems. Its primary interface is a graphical block diagramming tool and a customizable set of block libraries.

What is MATLAB integration? ›

If f is a symbolic expression, then. int(f) attempts to find another symbolic expression, F , so that diff(F) = f . That is, int(f) returns the indefinite integral or antiderivative of f (provided one exists in closed form).

What is the use of Integrator in MATLAB Simulink? ›

To support this computational model, the Integrator block saves its output at the current time step for use by the solver to compute its output at the next time step. The block also provides the solver with an initial condition for use in computing the block's initial state at the beginning of a simulation.

How do you integrate MATLAB code into Simulink? ›

You can integrate your MATLAB code into Simulink using the MATLAB Function block and MATLAB System block. Use MATLAB Function block to integrate simple functions. Use the MATLAB System block to integrate code that requires state dynamics, large streaming data interface, and interaction with the Simulink engine.

Can I add Simulink to MATLAB? ›

Download and install MATLAB, Simulink, and accompanying toolboxes and blocksets on a personal computer. Add toolboxes, products, apps, support packages, and other add-ons to an existing installation of MATLAB. Add products, update your current MATLAB installation, and update your license.

Why use Simulink instead of MATLAB? ›

Another factor to consider when choosing between Simulink blocks and MATLAB code is the speed and efficiency of your system. Simulink blocks can be faster and more efficient for some tasks, such as prototyping, testing, and debugging.

Do I need to know MATLAB for Simulink? ›

Simulink is for MATLAB Users

Use MATLAB and Simulink together to combine the power of textual and graphical programming in one environment. Apply your MATLAB knowledge to: Optimize parameters. Create new blocks.

What can Simulink be used for? ›

Simulink is the platform for Model-Based Design that supports system-level design, simulation, automatic code generation, and continuous test and verification of embedded systems. Key capabilities include: A graphical editor for modeling all components of a system.

What exactly is MATLAB used for? ›

MATLAB® is a programming platform designed specifically for engineers and scientists to analyze and design systems and products that transform our world. The heart of MATLAB is the MATLAB language, a matrix-based language allowing the most natural expression of computational mathematics.

How do you do integration? ›

Integration is the inverse process to differentiation. Some people call it anti-differentiation. Instead of multiplying the power at the front and subtracting one from the power, we add one to the power and then divide by the new power.

Is MATLAB the same as Python? ›

MATLAB is a commercial product, and licenses can be costly, especially for businesses and academic institutions. In contrast, Python is free and open-source, making it more cost-effective for individuals and organizations. Python's ecosystem benefits from a vast collection of free libraries and tools, reducing costs.

How does MATLAB and Simulink work? ›

Simulink provides a graphical editor, customizable block libraries, and solvers for modeling and simulating dynamic systems. It is integrated with MATLAB®, enabling you to incorporate MATLAB algorithms into models and export simulation results to MATLAB for further analysis.

What is the function of Simulink? ›

A Simulink® function is a computational unit that calculates a set of outputs when provided with a set of inputs. Since a Simulink function provides a common text interface to its function definition and a function caller, how you define the function is your choice.

What is the purpose of the integrator? ›

An integrator in measurement and control applications is an element whose output signal is the time integral of its input signal. It accumulates the input quantity over a defined time to produce a representative output. Integration is an important part of many engineering and scientific applications.

How to run Simulink simulation from MATLAB? ›

When you want to simulate the model using the current values for all model configuration parameter values, block parameter values, variable values, and so on, use the most basic syntax, specifying only the name of the model as an input argument. out = sim("ModelName"); This syntax returns a single Simulink.

How to use Simulink output in MATLAB? ›

On the Modeling tab, under Settings, click Model Settings. Then, in the Configuration Parameters dialog box, select Data Import/Export and select Single simulation output. You run a set of simulations using the Multiple Simulations pane. You simulate the model programmatically using one or more Simulink.

How to open MATLAB code in Simulink? ›

Open Saved Models
  1. In the MATLAB Editor, click Browse for folder . In the file browser that appears, navigate to the folder that contains the model and click Select Folder. ...
  2. Open Simulink. On the Simulink Start Page, in the side bar on the left, select a recent model or project from the list, or click Open.

References

Top Articles
Latest Posts
Article information

Author: Kerri Lueilwitz

Last Updated:

Views: 5916

Rating: 4.7 / 5 (47 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Kerri Lueilwitz

Birthday: 1992-10-31

Address: Suite 878 3699 Chantelle Roads, Colebury, NC 68599

Phone: +6111989609516

Job: Chief Farming Manager

Hobby: Mycology, Stone skipping, Dowsing, Whittling, Taxidermy, Sand art, Roller skating

Introduction: My name is Kerri Lueilwitz, I am a courageous, gentle, quaint, thankful, outstanding, brave, vast person who loves writing and wants to share my knowledge and understanding with you.