2
$\begingroup$

I have a function f in two variables y and theta, where y=z^2+x^2. There are numerical values for x,z,and theta ( x and z are the dimensions),I have to do calculations to obtain the velocity, so I need a way to express the vector of velocity in two components x and z separately.The following is a simple example of my task:

f[y_,θ_] = 2 y Cos θ + 4 y^2 (1 - 3 Cos θ)

gradf[y_, θ_] = Grad[f[y, θ], {y, θ}]

v[y_, θ_] = f[y, θ]/gradf[y, θ]

I made the below way, but it is not correct.

v[(z^2 + x^2) _, θ_] = f[y, θ]/gradf[y, θ]

I need separation of variables as components of vector, where:

z = {0.026239934196048018`, 0.031239934196048022`, 
 0.03623993419604802`, 0.04123993419604802`, 0.04623993419604802`, 
 0.05123993419604802`};
x = {-0.0065135092956195365`, -0.0065135092956195365`, 
-0.0065135092956195365`, -0.0065135092956195365`, 
-0.0065135092956195365`, -0.0065135092956195365`};

k = Sqrt[y]= Sqrt[z^2 + x^2]
θ = ArcCos[z/k]

Thank you.

$\endgroup$
6
  • 1
    $\begingroup$ Can you clarify what you want to do exactly? Do you just want to replace y by z^2+x^2 ? $\endgroup$
    – banone
    Jan 27, 2020 at 11:30
  • $\begingroup$ Hi Banone, My goal is to get the velocity in two variables z and x only. In other words, it is to obtain v [z_,x_] $\endgroup$
    – Fuad
    Jan 27, 2020 at 20:07
  • $\begingroup$ and what about θ? $\endgroup$
    – banone
    Jan 28, 2020 at 7:18
  • $\begingroup$ I already have numerical data for z,x, and θ. I don't know if I can evaluate the function using the values of θ and then the function will be v[(z^2 + x^2)] , so I'll get two parts (because of gradient) both of them in (z^2 + x^2). Then how can I obtain v[x_,z_]? $\endgroup$
    – Fuad
    Jan 28, 2020 at 14:00
  • $\begingroup$ Ok, I understand. I suggest making an interpolation function for θ(x,z) and include it in your definition. Can you provide your data or equivalent example data? $\endgroup$
    – banone
    Jan 28, 2020 at 14:43

1 Answer 1

1
$\begingroup$

I was wrong in the comments, since you have an analytical expression for θ, there is no need for an InterpolationFunction.

f[y_, θ_] = 2 y Cos[θ] + 4 y^2 (1 - 3 Cos[θ]);
gradf[y_, θ_] = Grad[f[y, θ], {y, θ}];
v0 = f[y, θ]/gradf[y, θ];

There was a typo, the Cos didn't have brackets in the first line, also I added v0 to save the evaluated expression before adding the other definitions:

y = z^2 + x^2;
k = Sqrt[z^2 + x^2];
θ = ArcCos[z/k];

Then you can just:

v[x_, z_] = v0

to evaluate the function you just map it to your x,z-data:

mesh = Transpose[{x, z}]
v[Sequence @@ #] & /@ mesh

or like this:

v[#[[1]], #[[2]]] & /@ mesh

Let me know if you have any questions.

$\endgroup$
1
  • $\begingroup$ Thank you very much! $\endgroup$
    – Fuad
    Jan 30, 2020 at 20:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.