MATLAB Mathematics - SERC - Index of
MATLAB Mathematics - SERC - Index of MATLAB Mathematics - SERC - Index of
4 Function Functions A three-dimensional plot of this curve is t = 0:0.1:3*pi; plot3(sin(2*t),cos(t),t) The arc length formula says the length of the curve is the integral of the norm of the derivatives of the parameterized equations 3π ∫ 0 2 4cos( 2t) The function hcurve computes the integrand function f = hcurve(t) f = sqrt(4*cos(2*t).^2 + sin(t).^2 + 1); Integrate this function with a call to quad len = quad(@hcurve,0,3*pi) len = 1.7222e+01 2 + sin( t) + 1 dt The length of this curve is about 17.2. Example: Double Integration Consider the numerical solution of ymax ∫ ymin xmax ∫ xmin fxy ( , ) dxdy For this example fxy ( , ) = ysin( x) + xcos( y) . The first step is to build the function to be evaluated. The function must be capable of returning a vector output when given a vector input. You must also consider which variable is in the inner integral, and which goes in the outer integral. In this example, the inner variable is x and the outer variable is y (the order in the integral is dxdy). In this case, the integrand function is function out = integrnd(x,y) out = y*sin(x) + x*cos(y); 4-28
Numerical Integration (Quadrature) To perform the integration, two functions are available in the funfun directory. The first, dblquad, is called directly from the command line. This M-file evaluates the outer loop using quad. At each iteration, quad calls the second helper function that evaluates the inner loop. To evaluate the double integral, use result = dblquad(@integrnd,xmin,xmax,ymin,ymax); The first argument is a string with the name of the integrand function. The second to fifth arguments are xmin xmax ymin ymax Lower limit of inner integral Upper limit of the inner integral Lower limit of outer integral Upper limit of the outer integral Here is a numeric example that illustrates the use of dblquad. xmin = pi; xmax = 2*pi; ymin = 0; ymax = pi; result = dblquad(@integrnd,xmin,xmax,ymin,ymax) The result is -9.8698. By default, dblquad calls quad. To integrate the previous example using quadl (with the default values for the tolerance argument), use result = dblquad(@integrnd,xmin,xmax,ymin,ymax,[],@quadl); Alternatively, you can pass any user-defined quadrature function name to dblquad as long as the quadrature function has the same calling and return arguments as quad. 4-29
- Page 80 and 81: 2 Polynomials and Interpolation −
- Page 82 and 83: 2 Polynomials and Interpolation 7 3
- Page 84 and 85: 2 Polynomials and Interpolation T =
- Page 86 and 87: 2 Polynomials and Interpolation Bec
- Page 88 and 89: 2 Polynomials and Interpolation Int
- Page 90 and 91: 2 Polynomials and Interpolation 2-3
- Page 92 and 93: 2 Polynomials and Interpolation 2-3
- Page 94 and 95: 3 Fast Fourier Transform (FFT) Intr
- Page 96 and 97: 3 Fast Fourier Transform (FFT) 200
- Page 98 and 99: 3 Fast Fourier Transform (FFT) 2 x
- Page 100 and 101: 3 Fast Fourier Transform (FFT) 500
- Page 102 and 103: 3 Fast Fourier Transform (FFT) Func
- Page 104 and 105: 4 Function Functions Function Summa
- Page 106 and 107: 4 Function Functions You can also c
- Page 108 and 109: 4 Function Functions 25 20 15 10 5
- Page 110 and 111: 4 Function Functions Minimizing Fun
- Page 112 and 113: 4 Function Functions To try fminsea
- Page 114 and 115: 4 Function Functions Plotting the R
- Page 116 and 117: 4 Function Functions The number of
- Page 118 and 119: 4 Function Functions and displays t
- Page 120 and 121: 4 Function Functions end function s
- Page 122 and 123: 4 Function Functions States of the
- Page 124 and 125: 4 Function Functions 100 80 60 40 2
- Page 126 and 127: 4 Function Functions You can verify
- Page 128 and 129: 4 Function Functions Troubleshootin
- Page 132 and 133: 4 Function Functions Parameterizing
- Page 134 and 135: 4 Function Functions “Anonymous F
- Page 136 and 137: 5 Differential Equations Initial Va
- Page 138 and 139: 5 Differential Equations odephas3 o
- Page 140 and 141: 5 Differential Equations This secti
- Page 142 and 143: 5 Differential Equations The basic
- Page 144 and 145: 5 Differential Equations 2 Code the
- Page 146 and 147: 5 Differential Equations function.
- Page 148 and 149: 5 Differential Equations One way to
- Page 150 and 151: 5 Differential Equations y0, yp0 Ve
- Page 152 and 153: 5 Differential Equations For exampl
- Page 154 and 155: 5 Differential Equations 1 0.8 0.6
- Page 156 and 157: 5 Differential Equations 2.5 Soluti
- Page 158 and 159: 5 Differential Equations To run thi
- Page 160 and 161: 5 Differential Equations 2 u′ i =
- Page 162 and 163: 5 Differential Equations dydt(i+1,:
- Page 164 and 165: 5 Differential Equations refine = 4
- Page 166 and 167: 5 Differential Equations Example: A
- Page 168 and 169: 5 Differential Equations function [
- Page 170 and 171: 5 Differential Equations Note The R
- Page 172 and 173: 5 Differential Equations 1 Robertso
- Page 174 and 175: 5 Differential Equations The MATLAB
- Page 176 and 177: 5 Differential Equations Summary of
- Page 178 and 179: 5 Differential Equations Problem Si
4 Function Functions<br />
A three-dimensional plot <strong>of</strong> this curve is<br />
t = 0:0.1:3*pi;<br />
plot3(sin(2*t),cos(t),t)<br />
The arc length formula says the length <strong>of</strong> the curve is the integral <strong>of</strong> the norm<br />
<strong>of</strong> the derivatives <strong>of</strong> the parameterized equations<br />
3π<br />
∫<br />
0<br />
2<br />
4cos( 2t)<br />
The function hcurve computes the integrand<br />
function f = hcurve(t)<br />
f = sqrt(4*cos(2*t).^2 + sin(t).^2 + 1);<br />
Integrate this function with a call to quad<br />
len = quad(@hcurve,0,3*pi)<br />
len =<br />
1.7222e+01<br />
2<br />
+ sin( t)<br />
+ 1 dt<br />
The length <strong>of</strong> this curve is about 17.2.<br />
Example: Double Integration<br />
Consider the numerical solution <strong>of</strong><br />
ymax<br />
∫<br />
ymin<br />
xmax<br />
∫<br />
xmin<br />
fxy ( , ) dxdy<br />
For this example fxy ( , ) = ysin( x)<br />
+ xcos( y)<br />
. The first step is to build the<br />
function to be evaluated. The function must be capable <strong>of</strong> returning a vector<br />
output when given a vector input. You must also consider which variable is in<br />
the inner integral, and which goes in the outer integral. In this example, the<br />
inner variable is x and the outer variable is y (the order in the integral is dxdy).<br />
In this case, the integrand function is<br />
function out = integrnd(x,y)<br />
out = y*sin(x) + x*cos(y);<br />
4-28