Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial derivatives, Rotor/Curl of a field, Normal of a surface #207

Open
NeatNit opened this issue Jul 2, 2019 · 5 comments
Open

Partial derivatives, Rotor/Curl of a field, Normal of a surface #207

NeatNit opened this issue Jul 2, 2019 · 5 comments

Comments

@NeatNit
Copy link

NeatNit commented Jul 2, 2019

Two separate-but-related differential operators that seem pretty important/essential to me for 3D math:

  1. Rotor/Curl - https://en.wikipedia.org/wiki/Curl_(mathematics)

I've managed to get the rotor of a given field at the point [X,Y,Z] in the following example:
https://www.math3d.org/MrIboI6x

Notice that I had to define 9 intermediate functions in order to accomplish this... not great fun. I also wasn't able to use this method to create a generic rotor function, because I had to use the constants X,Y,Z in the intermediate functions.

  1. Surface normal - https://en.wikipedia.org/wiki/Parametric_surface#Tangent_plane_and_normal_vector

(note that I mean the un-normalized vector Ru×Rv)

Again, I was able to do this for a single point using two intermediate functions: https://www.math3d.org/3Iqv6XXf

I've looked through math in the console and math.js, and wasn't able to find a ready-made way to calculate these at given coordinates. Please add one, and/or make an example of it so it's more discoverable!

What these two things have in common: they involve partial derivatives. I've tried using diff with functions of multiple variables, but I just can't find a way to work with them! If you can expose them a little better to the end-used, that might help.

@ChristopherChudzicki
Copy link
Owner

What these two things have in common: they involve partial derivatives. I've tried using diff with functions of multiple variables, but I just can't find a way to work with them! If you can expose them a little better to the end-used, that might help.

Yes, that's definitely an issue. I've always found working with partial derivatives a pain on Math3d. I haven't thought of a good, unambiguous syntax for partial derivatives, though. I'll start thinking about that again, though.

A curl function would be very easy to implement and I agree definitely a good idea. Probably it should accept syntax:

  • curl(f, x, y, z) where f is a function from R3 to R3, and x, y, z are scalars, or
  • curl(f, r) where f is same and r is a 3-component array

Also happy to do a surface normal function, though I'm not quite sure what to call it. Surface normal function would also be less crucial if better partial derivative support.

Question: Do you have any interest in making a PR for curl yourself? If not, that's totally: I really appreciate the time you've taken in making well thought-out suggestions in all these issues. If you would like a go at it, it's probably pretty similar to the implementation of unitT and I'm happy to give other feedback/advice. Otherwise, I'll tackle it in the next day or two.

@NeatNit
Copy link
Author

NeatNit commented Jul 3, 2019

While that is tempting and I would love to try and tackle it myself, I am currently in the start of exam period and probably can't afford to do this.

Possible syntax for partial diff: diff(f,x,y,z,2) would give the partial derivative based on the second parameter (in this case, y).

If you don't like to overload diff too much, you can call it pdiff perhaps ("partial diff").

As for surface normal - I agree is not as crucial if partial derivatives are more accessible, but it also wouldn't hurt. You can call it something like snormal ("surface normal").

Edit: discoverability will always be an issue, which is why I like the included examples and I think you (we?) should definitely make more of them.

@NeatNit
Copy link
Author

NeatNit commented Jul 3, 2019

I understand that diff(f,x,y,z) returns a matrix, where each partial derivative is a row (or column?) in the matrix, but I can't find a way to get one row(/column) of the matrix as a 3D vector. There is no row function, see josdejong/mathjs#230

Edit: I can't tell you how many failed attempts this took me: https://www.math3d.org/UdFijsnH

Apparently I was using subset/index wrong. To get the partial derivative of R(u,v) in regards to u, apparently we use:

Ru(u,v) = flatten(subset(diff(R,u,v),index(1,[1,2,3])))

I was stuck for hours trying to figure out why index(1,[1,3]) wasn't working. This would have been easier to solve if I could actually see the values that were being output.

This is related to the "see something's type" topic discussed here: #193 (comment), but for variables (that aren't functions) we might as well be able to see the actual output value - preferably as a nicely formatted matrix/table.

I know I'm making a lot of requests, some of which are big, but it's only because I like this software so much and want to see it improve. :)

(I will try to make some PRs eventually, but for the next ~month it will definitely not be possible)

Edit: Curl still requires partial derivatives as intermediate functions, but at least it can be made generic: https://www.math3d.org/bNLU7FfY - RotF(x,y,z) here works for any x,y,z.

@NeatNit
Copy link
Author

NeatNit commented Jul 10, 2019

I've just realized that the divergence of a field (Px + Qy + Rz, where F = P(x,y,z)i + Q(x,y,z)j + R(x,y,z)k) is also missing.

@ChristopherChudzicki
Copy link
Owner

ChristopherChudzicki commented Nov 22, 2019

Note to self: This is implemented but still needs documented examples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants