Using matlab to get vector fields and angles generated by a vector field on a closed curve?

Here is the system I want to build and get the vector field and the angles they create with the x-axis. I want to find the index of a closed curve.

The system

The system

The closed curve

I know how to do this in theory, choosing convenient points and looking at what the vector looks like at that point. Also I can always use

angles

to calculate angles. However, I am having problems with his code. Please do not tag me if the question is unclear. I ask about it how I understand it. I am new to Matlab. Can anyone point me in the right direction?

+3


source to share


1 answer


This is quite a daunting task for someone new to Matlab, I would recommend adopting some smaller tasks first so you get used to the matlab conventions.

That said, Matlab is all about numerical solutions, so unless you want to go the symbolic route of mathematics (in which case I would probably prefer Mathematica instead), your first task is to decide on the boundaries and granularity of your simulated space , then define them so you can apply your system of equations to it.

There are many ways to do this - some more efficient - but for ease of understanding I suggest the following:

First define axes separately

xpts = -10:0.1:10;
ypts = -10:0.1:10;
tpts = 0:0.01:10;

      

The syntax a: b: c gives a lower limit (a), an upper limit (c) and an interval (b), so you get 201 points for x. You can use the notation linspace

if it suits you, see it by typing doc linspace

in matlab.

Now you can create a grid of your coordinate points. You actually have three 3D matrices, one of which contains the x-coordinates of your space, and the others contain y and t. They look overkill, but it's worth it because you can use matrix operations on them.

[XX, YY, TT] = meshgrid(xpts, ypts, tpts);

      

Here you can perform any operations you like on these matrices. So, to compute x ^ 2.y, you could do

x2y = XX.^2 .* YY;

      

remembering that you will get a 3D matrix out of it, and all slices in the third dimension (corresponding to t) will be the same.

Some notes



Matlab has a nice built-in help system. You can enter "help functionname" for a quick prompt in the console or "doc function_name" to open the help browser for details and examples. They are really very good, they will help a lot.

I used XX and YY because that's just my preference, but I avoid single letter variable names as a general rule. You do not need.

Matrix multiplication is the default, so if you try XX*YY

, you won't get the answer you expect! To do multiplication by type, use the operator instead .*

. This will do a11 = b11 * c11, a12 = b12 * c12, ...

To raise each matrix element to a given cardinality, use the same .^

, not ^

the same reasons. Likewise, division.

You must make sure your matrices are correct for your operations. To do elementary operations on matrices, they must be of the same size. To perform matrix operations, they must follow the matrix sizing rules, as does the output. You will find a function size()

handy for debugging.

Construction of vector fields can be done with quiver

. To separate the components separately, you have more options: surf

, contour

and others. Look at the help docs and they will refer to similar types. The family plot

is mostly about lines, so they don't really help in fields without creative use of markers, colors and alphas.

To plot a curve or any other contour, you do not need to check the values ​​of the matrix - it will not work as expected anyway due to the level of detail - you can use a plot contour

with specific contour values.

Solving systems of dynamic equations is quite possible, but you will be doing numerical simulations and your results will again be subject to the granularity of your mesh. If you have closed solution forms like your phi expression, they might be easier to work with conceptually, but harder to work in Matlab.

This problem is painstaking in Matlab, but it comes with some uncharacteristic uses that are quite difficult to accomplish unless you have Matlab syntax. I would suggest starting with the 2nd grid instead of

[XX, YY] = meshgrid(xpts, ypts);

      

and calculate some functions of such as x ^ 2.y or x ^ 2 - y ^ 2. Prepare to plot them with quiver

or plot coordinates separately from intensity maps or surfaces.

+1


source







All Articles