CS计算机代考程序代写 matlab [Content_Types].xml

[Content_Types].xml

_rels/.rels

matlab/document.xml

matlab/output.xml

metadata/coreProperties.xml

metadata/mwcoreProperties.xml

metadata/mwcorePropertiesExtension.xml

metadata/mwcorePropertiesReleaseInfo.xml

MATLAB Differentiation In this livescript, you will learn how To compute derivatives numerically and symbolically using MATLAB. Numerical Differentiation As an example, we’ll consider the function f(x)=\frac{1}{x} (a) Analytically compute the derivative of f at x\in\{1,1.25,1.5,1.75,2\} . To compute the gradient of the vector of values, MATLAB has the function \texttt{gradient(F,h)} , where \texttt{F} are the function values and \texttt{h} are the spacings. The function uses central differencing for interior data points and single-sided differencing or he edges. If we consider 5 points between 1\leq x\leq 2 , we have N = 5;
x = linspace(1,2,N)
F = 1./x Since the grid spacing is given by x_{i+1}-x_{i}=h=0.25 , the numerical derivative is given as h = 1/(N-1);
gradient(F,h) (b) Run the previous commands and see how well the MATLAB function approximates the derivative. (c) Increase the number of sampling points and show that the numerical derivative converges to the exact value. \texttt{gradient()} also handles higher dimensional functions. Suppose that we want to compute the gradient of the scalar field \phi=\log{\sqrt{x^{2}+y^{2}}} which can be used to describe the flow of an inviscid fluid emerging from a source located at the origin. (d) Show that the gradient of \phi , \Big(\frac{\partial \phi}{\partial x},\frac{\partial\phi}{\partial y}\Big) , is given by \Big(\frac{\partial \phi}{\partial x},\frac{\partial\phi}{\partial y}\Big)
=
\Big(\frac{x}{x^{2}+y^{2}},\frac{y}{x^{2}+y^{2}}\Big) Plotting in vectors in MATLAB over the domain [-0.1,0.1]\times[-0.1,0.1] , we have x = -0.1:0.01:0.1;
y = -0.1:0.01:0.1;
[xx,yy] = meshgrid(x,y);
u = xx./(xx.^2+yy.^2);
v = yy./(xx.^2+yy.^2);

quiver(xx,yy,u,v) Using \texttt{gradient()} to approximate the gradient within the domain [-0.1,0.1]\times[-0.1,0.1] , we have phi = log(sqrt(xx.^2+yy.^2));
[phix,phiy] = gradient(phi,0.01);
phix(isinf(phix)) = NaN;
phiy(isinf(phiy)) = NaN; Plotting the vector field gives quiver(xx,yy,phix,phiy) Another important differential operator is the Laplacian \Delta=\nabla^{2}=\Big(\frac{\partial^{2}}{\partial x_{1}^{2}}+\frac{\partial^{2}}{\partial x_{2}^{2}}+\ldots+\frac{\partial^{2}}{\partial x_{N}^{2}}\Big) (e) Show that the Laplacian of \phi=\log{\sqrt{x^{2}+y^{2}}} is zero for x\neq(0,0) . In MATLAB this may be approximated using the \texttt{del2()} function. Again, the inputs are the function values and the grid spacing. To do this numerically, we have del2phi = del2(phi,0.01);

surf(xx,yy,del2phi) We see that the numerical approximation isn’t very good, but that’s expected considering that our grid spacing is quite coarse at \Delta=0.01 . (f) Modify the code to reduce \Delta to 0.001 . Symbolic Differentiation Symbolic differential equation is quite simple in MATLAB, which may be called using \texttt{diff(f,var,n)} , where \texttt{f} is the function we want to take the derivative of, \texttt{var} is the variable we want to take the derivative of, and \texttt{n} is the order of the derivative. For f(x)=\frac{1}{x} the derivative may be computed using syms x
diff(1/x,x,1) To compute the gradient of a scalar function (the source potential) \phi=\log{\sqrt{x^{2}+y^{2}}} we have syms x y
phi = log(sqrt(x^2+y^2));
[diff(phi,x,1) diff(phi,y,1)] And the Laplacian diff(phi,x,2)+diff(phi,y,2)

manual code ready 0.4 true false 0 16 16 false false 1 17 17 false false 2 19 19 false true 3 20 20 true false 4 33 33 false false 5 34 34 false false 6 35 35 false false 7 36 36 false false 8 37 37 false true 9 39 39 true false 10 42 42 false false 11 43 43 false false 12 44 44 false false 13 45 45 false true 14 47 47 true false 15 56 56 false true 16 56 56 true false 17 68 68 false true 18 69 69 true false 19 74 74 false false 20 75 75 false true 21 76 76 true true 22 79 79

2020-04-22T05:08:31Z 2020-09-20T02:52:28Z

application/vnd.mathworks.matlab.code MATLAB Code R2020b

9.9.0.1444674 c7fe238e-3a7c-4729-81a6-35f99a4c3580

9.9.0.1467703
R2020b

Aug 26 2020
2314982500