Calculation of the divergent rotational of a function in Matlab

Asked

Viewed 1,421 times

1

I have a college job where I have to create a routine to calculate the divergent rotational of any function in Matlab.

Researching, I found that I can use the function divergence() to calculate the user-imputed vector divergent.

I started the code:

clc 
clear

%Calcular o divergente da função

i = input('Insira o vetor i: ');
j = input('Insira o vetor j: ');
k = input('Insira o vetor k: ');

div = divergence(i,i,k);
printf(div);

When I insert some letter in the question, it returns the error below (put "2x"):

"Error using input Undefined Function or variable 'x'."

When I just enter numbers, I can get to the part where I calculate the divergent, but it makes that mistake:

"Error using divergence (line 54) U,V,W must all be a 3D arrays."

I would very much like your help, if possible!

Simply recalling that the divergent is calculated by the partial derivative of i in relation to x, j in relation to y and k in relation to z.

1 answer

0


You have two options here.

To be using 2*x is necessary to symbolic function of MATLAB.

If this is the case, you can use this direct example to help:

syms x y z; divergence([x^2 2*y z], [x y z])

If you want to use the same function but with the numeric mode, the setting is a little more complex and requires 3D matrices (reason for the error), generated using the meshgrid or with its function to define the 3D space.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.