MATLAB Examples

Fit a polynomial curve to a set of data using polyfit. Use the polyfit function to find the coefficients of a polynomial that fits a set of data in a least-squares sense using the syntax

This example was authored by the MathWorks community.

Utility from File Exchange

Define a function that visualizes the results of bfsearch and dfsearch by highlighting the nodes and edges of a graph.

Simulates the movements of a swarm to minimize the objective function

Gaussian fit using the least-squared solution in presence of known covariance

Demonstrates building and validating a short term electricity load forecasting model with MATLAB. The models take into account multiple sources of information including temperatures

F. Moisy, 9 july 2008. University Paris Sud.

This is the third script of 4 in the Natural Gas Storage Valuation case study. In this script, we calibrate a forward curve model to historical and options-derived forward curve data. The

This examples illustrates how to perform a FORM analysis on a discrete (0 or 1) failure response. In the example we'll compare a traditional Monte Carlo method with FORM. This example is was

Demonstrates building and validating a short term electricity price forecasting model with MATLAB using Neural Networks. The models take into account multiple sources of information

This script aims at demonstrating the capabilities and the syntax of simpletracker.m, a MATLAB function dedicated to tracking.

Demonstrates computing Value-at-Risk and Conditional Value-at-Risk (expected shortfall) for a portfolio using multivariate copula simulation with fat-tailed marginal

Coorous Mohtadi, MathWorks, 2012

David Young

Number of rows in healthy file must be the same as the number of rows in disease file. This reflects the fact that both must have measured the same number of quantities (genes, compounds, bugs,

This document explains how to use the state space MPC function which using input increment.

本プログラムでは、MATLAB上でSegNetを構築・学習し、 学習済みネットワークを評価するところまでのワークフローを試行します。 画像データは血液塗抹標本画像を利用し、写っている寄生虫の部分、赤血球の部分と それ以外の領域の3クラスに分類することを目的とします。 画像データは米国CDC DPDx Parasite Image

本プログラムでは、MATLAB上でFCN-AlexNetを構築・学習し、 学習済みネットワークを評価するところまでのワークフローを試行します。 画像データはCamVidデータセットを利用します。詳細についてはReference[1]をご覧ください。

This script reads in an image file and then attempts to find a green object in the image. It is designed to find one green ball and highlight that ball on the original image

Animates the vibration of a membrane, captures a series of screen shots, and saves the animation as a GIF image file.

All the scripts provided are used in Partial Differential Equation Methods for Image Inpainting (Carola-Bibiane Schoenlieb, Cambridge University Press, 2015):

Igor Podlubny (a), Tomas Skovranek (a), Blas M. Vinagre Jara (b)

Registers two images (2-D rigid translation) within a fraction of a pixel specified by the user. Instead of computing a zero-padded FFT (fast Fourier transform), this code uses selective

This script demonstrates using the included Talbot and Euler algorithms for numerical approximations of the inverse Laplace transform. The examples cover functions with known inverses

Copyright (c) 2008 Gabriel Peyre

This is the first script of 4 in the Natural Gas Storage Valuation case study. In this script, we import a data set of historical futures prices for natural gas, pre-process them and compute

This is the fourth script of 4 in the Natural Gas Storage Valuation case study. In this script, we value the storage facility using the rolling intrinsic optimization method. To do so, we

This demo was adapted from a 2009 digest article: Improving Optimization Performance with Parallel Computing

This tutotial shows how to use the SystemReliability object in COSSAN-X in order to estimate the failure probability of a parellel system. This tutorial is based on the example #5 (pag.271)

How many of you have successfully solved a Rubik's Cube® before? How long did you take to solve a cube that your friend scrambled? I have been able to successfully solve a Rubik's Cube, but have

This script demonstrates testing a simple technical indicator strategy and backtesting to optimize its parameters

Constraints set

Abstract:

These prototype MATLAB functions create and plot graphs from images based on neighbor relationships between pixels. You must have MATLAB R2015b to use them.

本プログラムでは、MATLAB上でCNNを構築・学習し、学習済みネットワークを評価するところまでの ワークフローを試行します。また、学習したネットワークを実装するために、CUDA C++コードを生成し、 既存のコードと統合して.exeを作成します。

Perform a reliability analysis on a cantilever beam. The documentation and the problem description of this example is available at:

Medical image segmentation using texture analysis

The Riemann problem of 1D elastodynamics

Script to Run Gary Vanderplaats cantilever Beam with slp_trust. N beam segments and 2N design variables, taken from Vanderplaats (1984) Example 5-1, pp. 147-150.

This script contains the examples shown in the webinar titled Optimization Tips and Tricks: Getting Started using Optimization with MATLAB presented live on 21 August 2008. To view the

State Space MPC code.

Format. The user can specify any number of digits to be carried, while doing a variety of different numerical computations on these numbers. Not all MATLAB operators are defined, as my main

Script to Run Gary Vanderplaats cantilever Beam with SQP and SLP. N beam segments and 2N design variables, taken from Vanderplaats (1984) Example 5-1, pp. 147-150.

Haftka, R. T. and Z. Gurdal (1992), Elements of Structural Optimization, Kluwer Academic Publishers

Example problem taken from Vanderplaats textbook, example 3-1. Unconstrained potential energy minimization of two springs. Complex-step gradient.

Backward-compatible with Optimization Toolbox version 1.0

This function creates a flattened image with overlayed mask (with transparency). The mask is applied with a specified color and transparency over the original image, and the resulting

Display a table of values for a gray-scale image.

Demonstrates an alternate model for building relationships between historical weather and load data to build and test a short term load forecasting. The model used is a set of aggregated

From: "Using Statistics and Optimization to Support Design Activities" Webinar, July 21, 2009.

How to use Cell Mode in the MATLAB Editor.

Called functions explicitlly shown in this function body: denoised_unwrap, phase_wrap.

The second term

Differintegral of a cubic polynomial using Fourier series representation

Plot function is optional argument first argument is a list of the population (columns are agents) second argument is a style for different phases: 'b.' for moving, 'r+' for cluster,'c*' for

By Jarek Tuszynski

First, the objective here is to find all of the negative real parts of the roots of a given polynomial with parameters. There is no restricition on the number of parameters, but for practical

In this tutorial a simple uncertainty quantification of a mechanical model of a long bridge is presented.

Perform optimization on the cantilever beam (TutorialCantileverBeamMatlab.html) using a MATLAB evaluator.

This script runs the Cantilever Beam Tutorial in OpenCOSSAN. The documentation and the problem description of this example is available at:

Perform optimization on the cantilever beam ( TutorialCantileverBeamMatlab.html ) using a MATLAB evaluator.

Parameters of the Riemann problem

Hock W., Schittkowski K. (1981): Test Examples for Nonlinear Programming Codes, Willi Hock, Klaus Schittkowski, Springer, Lecture Notes in Economics and Mathematical Systems, Vol. 187

AOE 5064 Homework #3, Problem 5a: SQP for Svanberg beam

Copyright 2015-2016 The MathWorks, Inc.Published with MATLAB® R2016a

Model, configure, generate AUTOSAR compliant code and export xml files using Simulink® and Embedded Coder®. The Vehicle Speed and Odometer calculations example demonstrates this

This is the second script of 4 in the Natural Gas Storage Valuation case study. This script prices a natural gas storage contract using the Intrinsic & Spread Option valuation methods. Please

A brief introduction to directional lapped orthogonal transforms

We demonstrate routines of the PROMPT package by modeling conformational motion between two conformations of calmodulin. To launch the example, use the following command:

The Dragon Curve is a fractal that was made famous in Jurassic Park , a novel by Michael Crichton.

The Dragon Curve is a fractal that was made famous in Jurassic Park, a novel by Michael Crichton.

The L8read function reads full-resolution Level 1 Landsat 8 images and has the ability to subset the image before loading.

Matlab_Abaqus_25_Bar_Truss is a Matlab source code which is used to find the optimum design of a 25-bar truss, described in section 2. It is developed by George Papazafeiropoulos

Find the cross-sections of the members of the 25-bar truss so that its weight is minimized and the constraints are satisfied. For more information please see the Documentation of

By F. Pedroche, M. Rebollo, C. Carrascosa and A. Palomares (2012) Universitat Politècnica de València (Spain)

How might one best compute the limit of a function at a specific point using numerical techniques? Since we need to compute a limit, the function will generally be singular in some fashion at

Beta is vector of regressors P(beta|D) ~ N(beta| mu, lambda) mu = lambda * X{transpose} * big_sigma^(-1) * Y lambda = (X{transpose} * inv(sigma) * X + inv(big_omega))^{-1}

Differintegral of a tabular function using Fourier series representation

The purpose of this demo is to reconstruct a simple picture of several polygons. I start by generating 'numOfPolygons' polygons of random colors ( left upper corner in the figure), say it's

The Padé approximant often gives better approximation of the function than truncating its Taylor series, and it may still work where the Taylor series does not converge. For these reasons

X_s=sym('x_s'); y_s= 2/(1+exp(-2*x_s))-1; %Eqn of hyperbolic tangent, from apply_transfer dy_s=diff(y_s,x_s); % Put into apply_transfer of modified file ddy_s=diff(dy_s,x_s); %

Add a description for your toolbox here.

This tutorial shows how to perform a Reliability Based Optimization on a cantilever beam. The goal of this tutorial is to optimize a clamped beam under tip load considering uncertainties.

In this tutorial the global sensitivity analysis is applied to a practical problem in structural engineering: a mechanical model of a long bridge.

This means no pennies. There are only 11 ways to do this.

Constitutive law in 1D elastodynamics

Svanberg, Krister, "The Method of Moving Asymptotes--A New Method for Structural Optimization," Intl. J. Num. Meth. Vol. 24, 1987, pp. 359-373.

Customer provided this example where he was puzzled why fmincon had a hard time finding the mimimum value.

This file describes the development of a failure boundary identication algorithm shown in "Using Statistics and Optimization to Support Design Activities" Webinar, July 21, 2009.

Find the cross-sections of the members of the 10-bar truss so that its weight is minimized and the constraints are satisfied. For more information please see the Documentation of

Matlab_Abaqus_10_Bar_Truss is a Matlab source code which is used to find the optimum design of a 10-bar truss, described in section 2. It is developed by George Papazafeiropoulos

This function performs cumulative mathematics on 2D matrices at arbitrary angles. This function works by using the Image Processing Toolbox function imrotate to rotate an input matrix to

Batchpleas is a wrapper for lsqnonlin, allowing it to solve many small problems (all with the same parameterization) in one batched, partitioned nonlinear least squares estimation. This

Computation of a limit usually involves a function that we cannot evaluate at the point of interest. It is often due to a singularity at the point of interest that we cannot evaluate the

Note that if we look at the points that are very close to z0, then the polynomial may have strange coefficients.

Non-negative least-squares solves the following problem:

This code is an applicatino of EMOO by using Genetic algorithms to solve the following simple constrained problem: Draw the biggest possible circle in a 2D space filled with stars without

This is a simple Evolutionary Multiobjective Optimization problem (two objectives).

This script provides a demo for th function linstretchrgb. This script is used to perform linear contrast stretching of a % 3-band image(FCC). The script is designed as a part of the laboraory

Differintegral of the identity function using Fourier series representation

Control vector parameterization, also known as direct sequential method, is one of the direct optimization methods for solving optimal control problems. The basic idea of direct

A MATLAB implementation of the Faddeev-Leverrier algorithm to compute the coefficients of the characteristic polynomial of a given matrix and to get the inverse of the matrix without extra

Customize the GraphPlot data cursor to display extra node properties of a graph.

This page contains two examples of solving nonstiff ordinary differential equations using ode45. MATLAB® has three solvers for nonstiff ODEs.

Construct and analyze a Watts-Strogatz small-world graph. The Watts-Strogatz model is a random graph that has small-world network properties, such as clustering and short average path

Write a simple event function for use with an ODE solver. The example file ballode models the motion of a bouncing ball. The events function halts the integration each time the ball bounces,

Use the directional components of an event function. The example file orbitode simulates a restricted three body problem where one body is orbiting two much larger bodies. The events

This page contains two examples of solving stiff ordinary differential equations using ode15s. MATLAB® has four solvers designed for stiff ODEs.

Fit a nonlinear function to data. For this example, the nonlinear function is the standard exponential decay curve

It is often useful to use a graphical format to view the distribution of the nonzero elements within a sparse matrix. The MATLAB spy function produces a template view of the sparsity

Split the integration domain to place a singularity on the boundary.

Plot the imaginary part versus the real part of a complex vector, z . With complex inputs, plot(z) is equivalent to plot(real(z),imag(z)) , where real(z) is the real part of z and imag(z) is the

You can use convolution to smooth 2-D data that contains high-frequency components.

The filter function is one way to implement a moving-average filter, which is a common data smoothing technique.

Integrate a set of discrete velocity data numerically to approximate the distance traveled. The integral family only accepts function handles as inputs, so those functions cannot be used

Use the Laplacian matrix of a graph to compute the Fiedler vector. The Fiedler vector can be used to partition the graph into two subgraphs.

The convhull and convhulln functions take a set of points and output the indices of the points that lie on the boundary of the convex hull. The point index-based representation of the convex

Interpolate scattered data when the value at each sample location is complex.

Perform nearest-neighbor interpolation on a scattered set of points using a specific Delaunay triangulation.

Modify the amplitude of a vector of data by applying a transfer function.

Calculate complex line integrals using the 'Waypoints' option of the integral function. In MATLAB®, you use the 'Waypoints' option to define a sequence of straight line paths from the first

Use the polyint function to integrate polynomial expressions analytically. Use this function to evaluate indefinite integral expressions of polynomials.

Add attributes to the nodes and edges in graphs created using graph and digraph . You can specify node names or edge weights when you originally call graph or digraph to create a graph. However,

Reduce the dimensionality of the grid plane arrays in 3-D to solve a 2-D interpolation problem.

The Voronoi diagram and the Delaunay triangulation on the same 2-D plot.

The alpha shape of a set of points is a generalization of the convex hull and a subgraph of the Delaunay triangulation. That is, the convex hull is just one type of alpha shape, and the full family

This topic shows how to constrain the solution of an ODE to be nonnegative. Imposing nonnegativity is not always trivial, but sometimes it is necessary due to the physical interpretation of

Interpolate three 1-D data sets in a single pass using griddedInterpolant . This is a faster alternative to looping over your data sets.

Interpolate two different samplings of the same parabolic function. It also shows that a better distribution of sample points produces better extrapolation results.

You can solve polynomial equations involving trigonometric functions by simplifying the equation using a substitution. The resulting polynomial of one variable no longer contains any

In optics, the Fourier transform can be used to describe the diffraction pattern produced by a plane wave incident on an optical mask with a small aperture [1]. This example uses the fft2

Represent a polynomial as a vector in MATLAB® and evaluate the polynomial at points of interest.

Extrapolate a well sampled 3-D gridded dataset using scatteredInterpolant . The query points lie on a planar grid that is completely outside domain.

Plot graphs, and then customize the display to add labels or highlighting to the graph nodes and edges.

Compute the convex hull of a 2-D point set using the alphaShape function.

Access and modify the nodes and/or edges in a graph or digraph object using the addedge , rmedge , addnode , rmnode , findedge , findnode , and subgraph functions.

Create and plot a 1-D interpolant using griddedInterpolant with a cubic interpolation method.

The Delaunay triangulation is well suited to scattered data interpolation problems because it has favorable geometric properties that produce good results. These properties are:

The convex hull of a set of points in N-D space is the smallest convex region enclosing all points in the set. If you think of a 2-D set of points as pegs in a peg board, the convex hull of that set

Perform linear interpolation on a scattered set of points with a specific Delaunay triangulation.

The relationship between a Delaunay triangulation of a set of points in 2-D and the convex hull of that set of points.

The Fourier transform is a mathematical formula that relates a signal sampled in time or space to the same signal sampled in frequency. In signal processing, the Fourier transform can reveal

Approximate gradients of a function by finite differences. It then shows how to plot a tangent plane to a point on the surface by using these approximated gradients.

Use the fzero function to find the roots of a polynomial in a specific interval. Among other uses, this method is suitable if you plot the polynomial and want to know the value of a particular

Use the polyint and polyder functions to analytically integrate or differentiate any polynomial represented by a vector of coefficients.

Use scatteredInterpolant to interpolate a scattered sampling of the peaks function.

Create and plot a 2-D interpolant using griddedInterpolant .

Create a 3-D interpolant and evaluate over a slice plane so you can plot the values on that plane.

Use the rng function, which provides control over random number generation.

How the Fourier series expansion for a square wave is made up of a sum of odd harmonics.

Create a griddedInterpolant and how to use it effectively to perform grid-based interpolation.

An application of sparse matrices and explains the relationship between graphs and matrices.

You can use the Fourier transform to analyze variations in data, such as an event in nature over a period time.

Analyze and visualize earthquake data.

Using polynomials of even modest degree to predict the future by extrapolating data is a risky business.

An interesting graphical approach to find out whether e^pi is greater than pi^e or not.

Compute and represent the finite difference Laplacian on an L-shaped domain.

The finite element mesh for a NASA airfoil, including two trailing flaps.

Use griddedInterpolant to resample the pixels in an image. Resampling an image is useful for adjusting the resolution and size, and you also can use it to smooth out the pixels after zooming.

How reordering the rows and columns of a sparse matrix can influence the speed and storage requirements of a matrix operation.

The use of the FFT function for spectral analysis. A common use of FFT's is to find the frequency components of a signal buried in a noisy time domain signal.

Interpolate data with a cubic spline in 2 dimensions. It uses the MATLAB® SPLINE function. It does NOT use the Curve Fitting Toolbox™ spline functions, which are a complete set of functions

Use ODE23 and ODE45 on a simple differential equation. ODE23 and ODE45 are functions for the numerical solution of ordinary differential equations. They employ variable step size

Use normalization to improve scattered data interpolation results with griddata . Normalization can improve the interpolation results in some cases, but in others it can compromise the

Perform arithmetic and linear algebra with single precision data. It also shows how the results are computed appropriately in single-precision or double-precision, depending on the

Perform arithmetic on integer data representing signals and images.

Create, edit, and query Delaunay triangulations using the delaunayTriangulation class. The Delaunay triangulation is the most widely used triangulation in scientific computing. The

Three of the 19 ways to compute the exponential of a matrix.

Formulate and solve three different types of differential equations using MATLAB®. MATLAB offers several numerical algorithms to solve a wide variety of differential equations.

Use a PageRank algorithm to rank a collection of websites. Although the PageRank algorithm was originally designed to rank search engine results, it also can be more broadly applied to the

Working with missing data is a common task in data preprocessing. Although sometimes missing values signify a meaningful event in the data, they often represent unreliable or unusable data

The optimal fitting of a nonlinear function to a set of data. It uses FMINSEARCH, an implementation of the Nelder-Mead simplex (direct search) algorithm, to minimize a nonlinear function of

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:

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

Contact your local office