MATLAB Code Week 10 PDF

Summary

This document provides MATLAB code examples for visualizing vector fields, calculating gradients, divergence, and curl in two and three dimensions. The document also contains some examples. The code demonstrates practical applications of vector calculus concepts

Full Transcript

Aim: ==== - To write Matlab codes to visualize the vector field of 2-Dimension as well as 3- Dimension. - To find the gradient vector and visualize it with contour curves. - To find divergence, curl and scalar potential MATLAB Syntax used: =================== +------------------------...

Aim: ==== - To write Matlab codes to visualize the vector field of 2-Dimension as well as 3- Dimension. - To find the gradient vector and visualize it with contour curves. - To find divergence, curl and scalar potential MATLAB Syntax used: =================== +-----------------------------------+-----------------------------------+ | | Constructs an inline function | | | object from the | | | | | | MATLAB expression contained in | | | the string expr. | +===================================+===================================+ | vectorize(fun) | Inserts a. before any \^, \* or | | | / in s. The result | | | | | | is a character string | +-----------------------------------+-----------------------------------+ | quiver(x,y,u,v) | components (u,v) at the points | | | (x,y) | +-----------------------------------+-----------------------------------+ | quiver3(x,y,z,u,v,w) | points (x,y,z)) | +-----------------------------------+-----------------------------------+ | vectarrow(p0,p1) | Plots a line vector with arrow | | | pointing from point p0 to point | | | p1. The function can plot | | | | | | both 2D and 3D vector with arrow | | | depending on the dimension of the | | | input | +-----------------------------------+-----------------------------------+ +-----------------------------------+-----------------------------------+ | [[g]](https://in.math | finds the gradient vector of the | | works.com/help/symbolic/sym.gradi | scalar function f with respect to | | ent.html?searchHighlight=gradient | a vector constructed from all | | &s_tid=srchtitle_gradient_2&mw_03 | symbolic scalar variables found | | 58c2bd-ebb0-43b0-8aed-800c2de8664 | in f. The | | 4) | | | = | order of variables in this vector | | gradient([f](https://in.mathworks | is defined by | |.com/help/symbolic/sym.gradient.h | [[symvar].](https://i | | tml?searchHighlight=gradient&s_ti | n.mathworks.com/help/symbolic/sym | | d=srchtitle_gradient_2&buiegd5-f) | var.html) | | ) | | +-----------------------------------+-----------------------------------+ **Vector Field - A vector field is an assignment of a vector to each point in a space, most commonly Euclidean space. A vector field on a plane can be visualized as a collection of arrows with given magnitudes and directions, each attached to a point on the plane. ** MATLAB Code: ============ Output: ======= -0.2 0 0.2 0.4 0.6 0.8 1 1.2 x Example 2: ========== MATLAB Code: ============ Output: ======= Example 3: ========== -1.5 1 0. 2 1 0 -1 MATLAB Code: ============ Output: ======= Inference: ========== Example 4 ========= Matlab code =========== Output: ======= Example 5 ========= Matlab code =========== Output: =======

Use Quizgecko on...
Browser
Browser