MATLAB Examples

Fit an exponential model to data using the fit function.

Use the fit function to fit a Gaussian model to data.

Fit and compare polynomials up to sixth degree using Curve Fitting Toolbox, fitting some census data. It also shows how to fit a single-term exponential equation and compare this to the

Use the fit function to fit polynomials to data. The steps fit and plot polynomial curves and a surface, specify fit options, return goodness of fit statistics, calculate predictions, and

Remove outliers when curve fitting programmatically, using the 'Exclude' name/value pair argument with the fit or fitoptions functions. You can plot excluded data by supplying an Exclude

Use the fit function to fit power series models to data.

Work with a curve fit.

Compute and plot prediction intervals at the command line.

Use the fit function to fit a Fourier model to data.

Compare the effects of excluding outliers and robust fitting. The example shows how to exclude outliers at an arbitrary distance greater than 1.5 standard deviations from the model. The

Fit a custom equation to census data, specifying bounds, coefficients, and a problem-dependent parameter.

Work with a surface fit.

Find the first and second derivatives of a fit, and the integral of the fit, at the predictor values.

The aim of this analysis is to characterize the dose response behavior of 4 different drug candidates in a population. The objective of this analysis is investigate the how the treatments

This demo is an example of performing data mining on historical fuel economy data. We have data from various cars built from year 2000 up to 2012.

Goal - Produce a reliable med term forecasting model for Energy Demand

This example was authored by the MathWorks community.

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

データは以下ページから取得したオープンデータを使用

緯度

The aim of this demo is to characterize the "complete spectrum of interaction" between opiods and hypnotics, using propofol and remifentanil as drug class prototypes [1]. 4 different

Use the csaps and spaps commands from Curve Fitting Toolbox™ to construct cubic smoothing splines.

Use commands from Curve Fitting Toolbox™ to fit a spline to titanium test data with manual and automatic selection of knots.

Fit a function to data using lsqcurvefit together with MultiStart.

Find the minimum of Rastrigin's function restricted so the first component of x is an integer. The components of x are further restricted to be in the region .

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

Simulates the movements of a swarm to minimize the objective function

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

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

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

Optimize using the particleswarm solver. The particle swarm algorithm moves a population of particles called a swarm toward a minimum of an objective function. The velocity of each

How @gacreationlinearfeasible, the default creation function for linearly constrained problems, creates a population for ga. The population is well-dispersed, and is biased to lie on

Solve a mixed integer engineering design problem using the Genetic Algorithm (ga) solver in Global Optimization Toolbox.

The use of a custom output function in the genetic algorithm solver ga. The custom output function performs the following tasks:

Create and manage options for the multiobjective genetic algorithm function gamultiobj using optimoptins in Global Optimization Toolbox.

Perform a multiobjective optimization using multiobjective genetic algorithm function gamultiobj in Global Optimization Toolbox.

Create and minimize a fitness function using the Genetic Algorithm in the Global Optimization Toolbox.

Minimize an objective function subject to nonlinear inequality constraints and bounds using the Genetic Algorithm.

Use the genetic algorithm to minimize a function using a custom data type. The genetic algorithm is customized to solve the traveling salesman problem.

Create and manage options for the genetic algorithm function ga using optimoptions in the Global Optimization Toolbox.

Use a hybrid scheme to optimize a function using the Genetic Algorithm and another optimization method. ga can reach the region near an optimum point relatively quickly, but it can take many

Create and minimize an objective function using Simulated Annealing in the Global Optimization Toolbox.

Create and manage options for the simulated annealing function simulannealbnd using optimoptions in the Global Optimization Toolbox.

Use simulated annealing to minimize a function using a custom data type. Here simulated annealing is customized to solve the multiprocessor scheduling problem.

Use the functions GlobalSearch and MultiStart.

Load and modify data using Model-Based Calibration Toolbox™ command-line interface. Data can be loaded from files (Excel® files, MATLAB® files, text files) and from the MATLAB®

Use the Model-Based Calibration Toolbox™ command-line functionality for point-by-point engine modeling projects.

Automatically generate an mbcmodel project for the gasoline case study using the command-line tools in Model-Based Calibration Toolbox™ .

Design an experiment for the gasoline case study problem using the command-line interface to Model-Based Calibration Toolbox™. The gasoline case study describes how to systematically

Create an optimal design for a polynomial model using Model-Based Calibration Toolbox™ command-line interface.

Create and apply constraints to a design using Model-Based Calibration Toolbox™ command-line interface.

Use the command-line functionality to generate local designs at each global operating point. This particular example shows how you can produce local maps for a diesel engine calibration.

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

State Space MPC code.

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

Load the sample data.

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); %

A linear neuron is trained to find y non-unique solution to an undetermined problem.

A linear neuron is trained to find the minimum sum-squared error linear fit to y nonlinear input/output problem.

A linear neuron is designed to respond to specific inputs with target outputs.

A linear neuron is allowed to adapt so that given one signal, it can predict a second signal.

A linear neuron is trained to respond to specific inputs with target outputs.

A linear neuron is trained to find the minimum error solution for y problem with linearly dependent input vectors. If y linear dependence in input vectors is not matched in the target vectors,

A linear neuron is trained to find the minimum error solution for a simple problem. The neuron is trained with the learning rate larger than the one suggested by MAXLINLR.

Illustrates how a self-organizing map neural network can cluster iris flowers into classes topologically, providing insight into the types of flowers and a useful tool for further

Demonstrates looking for patterns in gene expression profiles in baker's yeast using neural networks.

A radial basis network is trained to respond to specific inputs with target outputs. However, because the spread of the radial basis neurons is too high, each neuron responds essentially the

Uses functions NEWPNN and SIM.

Uses the NEWRB function to create a radial basis network that approximates a function defined by a set of data points.

A radial basis network is trained to respond to specific inputs with target outputs. However, because the spread of the radial basis neurons is too low, the network requires many neurons.

Uses functions NEWGRNN and SIM.

An LVQ network is trained to classify input vectors according to given targets.

Neurons in a competitive layer learn to represent different regions of the input space where input vectors occur.

Neurons in a 2-D layer learn to represent different regions of the input space where input vectors occur. In addition, neighboring neurons learn to respond to similar inputs, thus the layer

As in DEMOSM1, this self-organizing map will learn to represent different regions of the input space where input vectors occur. In this example, however, the neurons will arrange

Illustrates how a pattern recognition neural network can classify wines by winery based on its chemical characteristics.

Illustrates how to train a neural network to perform simple character recognition.

We propose two fuzzy portfolio optimization models based on the Markowitz Mean-Variance approach. The first model involves trapezoidal fuzzy numbers to extent statistical data, which

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

Time series of acceleration records are simulated using a stationnary process that is "weighted" by an envelopp function. The function that fullfills this procedure is 'seismSim'.

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

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

Solve portfolio optimization problems using the interior-point quadratic programming algorithm in quadprog. The function quadprog belongs to Optimization Toolbox™.

Determine the shape of a circus tent by solving a large-scale quadratic optimization problem. The shape of a circus tent is determined by a constrained optimization problem. We will solve

Solve an assignment problem by binary integer programming using the intlinprog function.

Use binary integer programming to solve the classic travelling salesman problem. This problem involves finding the shortest closed tour (path) through a set of stops (cities). In this case

Solve a Sudoku puzzle using binary integer programming.

Set up and solve a mixed-integer linear programming problem. The problem is to find the optimal production and distribution levels among a set of factories, warehouses, and sales outlets.

Solve a Mixed-Integer Quadratic Programming (MIQP) portfolio optimization problem using the intlinprog Mixed-Integer Linear Programming (MILP) solver. The idea is to iteratively

Schedule two gas-fired electric generators optimally, meaning to get the most revenue minus cost. While the example is not entirely realistic, it does show how to take into account costs

How to speed up the minimization of an expensive optimization problem using functions in Optimization Toolbox™ and Global Optimization Toolbox. In the first part of the example we solve the

Use two nonlinear optimization solvers and how to set options. The nonlinear solvers that we use in this example are fminunc and fmincon.

Perform nonlinear fitting of complex-valued data. While most Optimization Toolbox™ solvers and algorithms operate only on real-valued data, least-squares solvers and fsolve can work on

Fit a nonlinear function to data using several Optimization Toolbox™ algorithms.

Recover a blurred image by solving a large-scale bound-constrained linear least-squares optimization problem.

Solve the wave equation using command-line functions. It solves the equation with boundary conditions u = 0 at the left and right sides, and at the top and bottom. The initial conditions are

Solve Poisson's equation using command-line functions. The code compares the solution with an analytic solution, and refines the mesh until the solutions are close.

Solve for the heat distribution in a metal block with cavity using command-line functions. For the PDE app solution, see Heat Equation for Metal Block with Cavity: PDE app.

Compute the eigenvalues and eigenmodes of a square domain using command-line functions. The geometry description file file for this problem is called squareg.m.

Analyze an idealized 3-D mechanical part under an applied loading using Finite Element Analysis (FEA). The objective of the analysis is to determine the maximum deflection caused by the

This examples conducts a parametric study in which heat conduction simulation is performed over a set of similar geometries to determine which geometry "best" meets an average temperature

Calculate the deflection of a structural plate acted on by a pressure loading using the Partial Differential Equation Toolbox™.

Solve the heat equation with a source term using the solvepde function in the Partial Differential Equation Toolbox™.

How a 3-D axisymmetric model can be analyzed using a 2-D model. The model geometry, material properties, and boundary conditions must all be symmetric about a single axis for this

Perform a heat transfer analysis of a thin plate using the Partial Differential Equation Toolbox™.

An idealized thermal analysis of a rectangular, metal block with a rectangular cavity in the center. One of the purposes of this example is to show how temperature-dependent thermal

Solve a coupled elasticity-electrostatics problem using Partial Differential Equation Toolbox™. Piezoelectric materials deform when a voltage is applied. Conversely, a voltage is

Include damping in the transient analysis of a simple cantilever beam analyzed with the Partial Differential Equation Toolbox™. The beam is modeled with a plane stress elasticity

Analyze an idealized 3-D mechanical part under an applied load using Finite Element Analysis (FEA). The objective of the analysis is to determine the maximum deflection caused by the load.

Calculate the vibration modes and frequencies of a 3-D simply supported, square, elastic plate. The dimensions and material properties of the plate are taken from a standard finite element

The Partial Differential Equation Toolbox™ analysis of the dynamic behavior of a beam clamped at both ends and loaded with a uniform pressure load. The pressure load is suddenly applied at

The calculation of the vibration modes of a circular membrane. The calculation of vibration modes requires the solution of the eigenvalue partial differential equation (PDE). In this

Numerically solve a Poisson's equation using the assempde function in the Partial Differential Equation Toolbox™ in conjunction with domain decomposition.

Create contour slices in various directions through a solution in 3-D geometry.

Solves a Poisson's equation with a delta-function point source on the unit disk using the adaptmesh function in the Partial Differential Equation Toolbox™.

Numerically solve a Poisson's equation using the solvepde function in Partial Differential Equation Toolbox™.

Use anovan to fit models where a factor's levels represent a random selection from a larger (infinite) set of possible levels.

Generate a nonlinear classifier with Gaussian kernel function. First, generate one class of points inside the unit disk in two dimensions, and another class of points in the annulus from

Compute and plot the pdf of a Poisson distribution with parameter lambda = 5.

In this example, use a database of 1985 car imports with 205 observations, 25 predictors, and 1 response, which is insurance risk rating, or "symboling." The first 15 variables are numeric

Use Cook's Distance to determine the outliers in the data.

Use copulafit to calibrate copulas with data. To generate data Xsim with a distribution "just like" (in terms of marginal distributions and correlations) the distribution of data in the

Perform linear and quadratic classification of Fisher iris data.

Similar to the bootstrap is the jackknife, which uses resampling to estimate the bias of a sample statistic. Sometimes it is also used to estimate standard error of the sample statistic. The

Perform N-way ANOVA on car data with mileage and other information on 406 cars made between 1970 and 1982.

Find the indices of the three nearest observations in X to each observation in Y with respect to the chi-square distance. This distance metric is used in correspondence analysis,

Plot the pdf of a bivariate Student's t distribution. You can use this distribution for a higher number of dimensions as well, although visualization is not easy.

Compute and plot the pdf using four different values for the parameter r, the desired number of successes: .1, 1, 3, and 6. In each case, the probability of success p is .5.

As for all discrete distributions, the cdf is a step function. The plot shows the discrete uniform cdf for N = 10.

Use a random subspace ensemble to increase the accuracy of classification. It also shows how to use cross validation to determine good parameters for both the weak learner template and the

You can also use ensembles of decision trees for classification. For this example, use ionosphere data with 351 observations and 34 real-valued predictors. The response variable is

Uses the data on cars in carsmall.mat to create a regression tree for predicting mileage using measurements of weight and the number of cylinders as predictors. Here, one predictor (weight)

Test for the significance of the regression coefficients using t-statistic.

When you have missing data, trees and ensembles of trees give better predictions when they include surrogate splits. Furthermore, estimates of predictor importance are often different

Use cmdscale to perform classical (metric) multidimensional scaling, also known as principal coordinates analysis.

Compute and plot the pdf of a multivariate normal distribution.

Display R-squared (coefficient of determination) and adjusted R-squared. Load the sample data and define the response and independent variables.

Fit a linear regression model. A typical workflow involves the following: import data, fit a regression, test its quality, modify it to improve the quality, and share it.

Use functional derivatives in the Symbolic Math Toolbox™ using the example of the wave equation. The wave equation for a string fixed at its ends is solved using functional derivatives. A

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

This code solves a test problem involving a Poisson equation on a square domain. The method relies on Lagrangian finite elements on a uniform triangular mesh. The solver is documented in the

This code solves the test problem of a thermally driven flow in a rectangular enclosure with an aspect ration of 8:1, as described in Christon et al. (2002). The method relies on Taylor-Hood

This file contains an explanation of the difference between implicit and explicit time integration schemes. The content is intended for those who want to learn a bit more than what the

This code solves a test problem involving a Burgers equation on a square domain, described in "Singler (2014). The method relies on linear Lagrangian finite elements on a uniform triangular

Provides an overview of the Symbolic Math Toolbox which offers a complete set of tools for computational and analytical mathematics.

Demonstrates that the Symbolic Math Toolbox helps minimize errors when solving a nonlinear system of equations.

Do rotations and transforms in 3D using Symbolic Math Toolbox™ and matrices.

Create a 3-D surface by using fsurf.

Plot 3-D parametric lines by using fplot3.

Plot equations and implicit functions using fimplicit.

Create a 2-D line plot by using fplot. Plot the expression .

Extracts closed-form solutions for the coefficients of frequencies in an output signal. The output signal results from passing an input through an analytical nonlinear transfer

Use a Padé approximant in control system theory to model time delays in the response of a first-order system.

Explores basic arbitrage concepts in a single-period, two-state asset portfolio. The portfolio consists of a bond, a long stock, and a long call option on the stock.

Obtains the partial differential equation that describes the expected final price of an asset whose price is a stochastic process given by a stochastic differential equation.

Develops a mathematical model using the Symbolic Math Toolbox to undistort an image and features a local function in the live script.

Finds the average radiation power of two attracting charges moving in an elliptical orbit (an electric dipole ).

Model the velocity of a paratrooper that is dropped from an airplane.

Uses Symbolic Math Toolbox and the Statistics and Machine Learning Toolbox to explore and derive a parametric analytical expression for the average power generated by a wind turbine.

Use variable-precision arithmetic to investigate the decimal digits of \pi using Symbolic Math Toolbox™.

Get precise values for binomial coefficients and find probabilities in coin-tossing experiments using the Symbolic Math Toolbox™ .

Choose your country 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 location from the following list:

See all countries