Calculation of the divergent rotational of a function in Matlab

1

I'm having a college assignment where I should create a routine to calculate the divergent rotational of any function in matlab.

Searching, I found that I can use the divergence() function to calculate the divergent of the vectors imputed by the user.

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 enter some letter in the question, it returns the error below (I put "2x"):

  

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

When I enter only numbers, I get to the part of calculating the divergent, but it gives this error:

  

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

I would greatly appreciate your help if possible!

Just remembering that the divergent is computed by the partial derivative of i in relation to x, j in relation to y and k with respect to z.

    
asked by anonymous 27.05.2017 / 18:07

1 answer

0

You have two options here.

To be using 2*x you need the MATLAB symbolic function .

If this is the case, you can use this example directly 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 numeric mode, the definition is a bit more complex and requires 3D arrays (reason for the error), generated using meshgrid or its function to define the 3D space .

    
26.08.2017 / 23:49