I would like to verify the divergence theorem in MATLAB - matlab

I would like to verify the divergence theorem if F(x, y, z) =<x^2y^2, y^2z^2 , z^2x^2> when the solid E is bounded by x^2 + y^2 + z^2 = 2 on top and z = (x^2+y^2)^1/2 on the bottom in MATLAB.
I know the function for the divergence but I need help with setting up the bounds.
syms x y z F(x,y,z)=[x^2y^2, y^2z^2, z^2x^2]; div=divergence(F,[x,y,z])
Thank you in advance!

try this
Divergence Theorem (Gauss’, Ostrogradsky’s) to Measure Flow
version 1.0.0 (2.62 KB) by Roche de Guzman
https://uk.mathworks.com/matlabcentral/fileexchange/70371-divergence-theorem-gauss-ostrogradsky-s-to-measure-flow?s_tid=srchtitle_divergence%2520theorem_2

Related

How to create a third degree polynomial in x and y in matlab?

I was going through matlab docs and it's mentioned that a polynomial can be created and evaluated as mentioned in this doc
However, I would like to create a third degree polynomial in x and y. Example: f(x, y) = x^3 + y^3 + 3x^2y + 3xy^2.
How do we create a third degree polynomial in x and y, like the example above?
The link you post is for creating a vector of coefficients for a polynomial of one variable. For two variables like you have, could you just use a function handle? E.g.,
f = #(x, y) x.^3 + y.^3 + 3*x.^2.*y + 3*x.*y.^2

Y from X dependency in Matlab

I have solved a system of differential equations and got the answer:
x(t) = -C1exp(-t) + C2exp(3*t)/3
y(t) = C1exp(-t) + C2exp(3*t)
X and y depend on t. How can I plot the y(x) graph?

solve integral symbolic in Matlab

I would like to symbolically solve an integral in Matlab. But Matlab doesn't solve my equation.
The term I want to take integral is : x ^2 * exp(-lambda*x)/ (x+w+tau)
Here is my code:
syms x
f = x ^2 * exp(-lambda*x)/ (x+w+tau);
F = int(f,0,lambda)
pretty(F)
Matlab does not solve it, instead gives me the folowing:
F =
int((x^2*exp(-lambda*x))/(tau + w + x), x, 0, lambda)

Is it possible to offset a plot using ezplot?

I am trying to offset a plot after plotting using ezplot in x- direction by 10 units.
syms x y;
f1= x^2 + y^2 - (6*y/5)-1/16;
h = ezplot(f1,[-.25 .25 0 1.25]);
I am unable to resolve this issue on my own. Any help or links to relevant documentation would be greatly appreciated.
There's no way you can do that other than manually offsetting the plot yourself in f1 by:
syms x y;
f1 = (x - 10)^2 + y^2 - (6*y/5) - 1/16; % Shift x coordinate to the right by 10
h = ezplot(f1, [10-0.25 10+0.25 0 1.25]); % Note the shift in the x limits
Remember that ezplot's job is to plot an equation for you. You can't simply shift the points when you're done plotting.... actually you can't really do that with any of the MATLAB plot mechanisms because the job is simply to either plot points in arrays or matrices, or in your case for ezplot to plot the equations.

Drawing decision boundary of two multivariate gaussian

I am trying to plot something similar to below:
I am using Matlab. I achieved drawing contour plots. However I could not draw the discriminant. Can anyone show a sample Matlab code or give some idea to draw the discriminant?
If you know the probability density function of each of the gaussian for a given point (x,y), lets say its pdf1(x,y) and pdf2(x,y) then you can simply plot the contour line of f(x,y) := pdf1(x,y) > pdf2(x,y). So you define function f to be 1 iff pdf1(x,y)>pdf2(x,y). This way the only contour will be placed along the curve where pdf1(x,y)==pdf2(x,y) which is the decision boundary (discriminant). If you wish to define "nice" function you can do it simply by setting f(x,y) = sgn( pdf1(x,y) - pdf2(x,y) ), and plotting its contour plot will result in exact same discriminant.
Here is how I would solve this problem analytically: you equate these two discriminant functions
g1(x)=x' W1 x + w1' x + w10
g2(x)=x' W2 x + w2' x + w20
g1(x) = g2(x)
==> x' (W2 - W1) x + (w2-w1)'x + w20 - w10
then, I consider W2 - W1 to have be this matrix
W2-W1 = [a b; c d]
which then by expanding vector x=[x1 x2]', we get:
a x1^2 + (b+c) x1 x2 + d x2^2 + (w21-w11) x1 + (w22-w12) x2 + w20-w10 = 0
this is the equation of an ellipse, so you can simplify it into the form below:
(x1 - a0)^2/h + (x2-b0)^2/g = r^2
Or, you can assume that you know the range of x1 for example x1=[-2:0.1:2], and then solve the parabola