Discussion Closed This discussion was created more than 6 months ago and has been closed. To start a new discussion with a link back to this one, click here.

Differentiation

Please login with a confirmed email address before reporting spam

Hi all,

Is it possible to differentiane an expression in variable field itself.

I have defined a variable: es.modE = (es.Ex)^2+(es.Ex)^2+(es.Ex)^2 (where es.Ex is x component of electric field etc..)

now, I need to define another variable, lets say : f_DEP = partial derivative of (es.modE) wrt x.

how can i express f_DEP in the variable field. I am using COMSOL4

plz reply asap


18 Replies Last Post Oct 12, 2016, 9:44 a.m. EDT

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Oct 9, 2010, 12:50 p.m. EDT
never mind.. was able to resolve the problem..
never mind.. was able to resolve the problem..

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Oct 9, 2010, 10:55 p.m. EDT
Hi,Adityendra Suman,

I also met this kind problem. What I did is exlport the data and calculate in the Matlab.

I would appreciate it if you can tell me how to do this in Comsol without matlab.

Cheers,


never mind.. was able to resolve the problem..


Hi,Adityendra Suman, I also met this kind problem. What I did is exlport the data and calculate in the Matlab. I would appreciate it if you can tell me how to do this in Comsol without matlab. Cheers, [QUOTE] never mind.. was able to resolve the problem.. [/QUOTE]

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Oct 10, 2010, 3:39 a.m. EDT
There is a mathematical operator : d(f,x) ----- for differentiating a function f wrt x
and : pd(f,x) ------ for partially differentiating the function f wrt x

you can search "mathematical operator" in help desk to know more.


in my case, i wrote: f_DEP = pd(es.modE , x)
There is a mathematical operator : d(f,x) ----- for differentiating a function f wrt x and : pd(f,x) ------ for partially differentiating the function f wrt x you can search "mathematical operator" in help desk to know more. in my case, i wrote: f_DEP = pd(es.modE , x)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Apr 22, 2011, 3:37 p.m. EDT
Hi,

I have followed your steps that defined a variables, es.modE = (es.Ex)^2+(es.Ex)^2+(es.Ex)^2 and f_DEP = pd(es.modE,x), in the local definitions of variable.

But the plot of the f_DEP is always zero at everywhere.

May you advice me what the mistakes I have possibly made?

Looking for your reply in soonest.

Thanks and regards,
Woon Huei.
Hi, I have followed your steps that defined a variables, es.modE = (es.Ex)^2+(es.Ex)^2+(es.Ex)^2 and f_DEP = pd(es.modE,x), in the local definitions of variable. But the plot of the f_DEP is always zero at everywhere. May you advice me what the mistakes I have possibly made? Looking for your reply in soonest. Thanks and regards, Woon Huei.

Ivar KJELBERG COMSOL Multiphysics(r) fan, retired, former "Senior Expert" at CSEM SA (CH)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Apr 22, 2011, 5:44 p.m. EDT
Hi

Why not use the internal variable "es.normE", it's calculated such that it remains correct even if the E is complex, which is not the case for your "es.modE"

as es.Ex = -Vx where V is the dependent variable for the voltage, it's already derived via a derivation, hence it becomes easily somewhat "noisy" or "stepwise like"

the derivative of Ex (where (Ex,Ey,Ez) are the scalar values for the global coordinate components of the vector "E") can be expressed via the Vxx ... the second derivatives of V (provided you use at least quadratic shape functions)

--
Good luck
Ivar
Hi Why not use the internal variable "es.normE", it's calculated such that it remains correct even if the E is complex, which is not the case for your "es.modE" as es.Ex = -Vx where V is the dependent variable for the voltage, it's already derived via a derivation, hence it becomes easily somewhat "noisy" or "stepwise like" the derivative of Ex (where (Ex,Ey,Ez) are the scalar values for the global coordinate components of the vector "E") can be expressed via the Vxx ... the second derivatives of V (provided you use at least quadratic shape functions) -- Good luck Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Apr 26, 2011, 1:43 p.m. EDT
Hi Ivar,

Thanks for your reply.

From my knowledge, Derivative of electric field is equal to the sum of partial derivative of electric field respect to x, y and z directions.

I am wondering whether Vxx is the derivative of electric field respect to x or partial derivative of electric field respect to x.

If it is derivative of electric field respect to x if it is not used for analysing derivative of electric field.

Thanks and regards,
Woon Huei.
Hi Ivar, Thanks for your reply. From my knowledge, Derivative of electric field is equal to the sum of partial derivative of electric field respect to x, y and z directions. I am wondering whether Vxx is the derivative of electric field respect to x or partial derivative of electric field respect to x. If it is derivative of electric field respect to x if it is not used for analysing derivative of electric field. Thanks and regards, Woon Huei.

Ivar KJELBERG COMSOL Multiphysics(r) fan, retired, former "Senior Expert" at CSEM SA (CH)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Apr 26, 2011, 2:22 p.m. EDT
Hi

Vxx is the SECOND derivative of the SCALAR potential V.

Ex (the scalar x component of VECTOR E) is equal to (minus) the FIRST derivative of the scalar V along x,

Vxx is also the FIRST derivative of the scalar component Ex

in math notations
Vx = dV/dx,
Vxx = d^2V/dx^2,
Ex = -Vx, and
d(Ex)/dx = -Vxx

in vector notation E = -grad(V)

At least that is how I understand things

You can also check the underlying equations of COMSOL

--
Good luck
Ivar
Hi Vxx is the SECOND derivative of the SCALAR potential V. Ex (the scalar x component of VECTOR E) is equal to (minus) the FIRST derivative of the scalar V along x, Vxx is also the FIRST derivative of the scalar component Ex in math notations Vx = dV/dx, Vxx = d^2V/dx^2, Ex = -Vx, and d(Ex)/dx = -Vxx in vector notation E = -grad(V) At least that is how I understand things You can also check the underlying equations of COMSOL -- Good luck Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Aug 17, 2011, 11:37 a.m. EDT
Hi Woon Huei,

I am having the same issue as you (plots show zero everywhere). Were you able to find a solution?

Thanks in advance,
Becky
Hi Woon Huei, I am having the same issue as you (plots show zero everywhere). Were you able to find a solution? Thanks in advance, Becky

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jul 5, 2012, 6:20 p.m. EDT
It seems like a very common thing, I have the same problem for now.
It seems like a very common thing, I have the same problem for now.

Ivar KJELBERG COMSOL Multiphysics(r) fan, retired, former "Senior Expert" at CSEM SA (CH)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jul 6, 2012, 3:21 a.m. EDT
Hi

have you checked that your discretisation is high enough to get a non zero derivatives?

Depending on which "dependent variable" you have you can only derive 2x in standard 2md order discretization, and you wil get step funtions, you need to get higher discrtisation to get smoother or higher derivatives. And several physics in the ACDC domain you work already by default on the derivative of the true solved varable field

--
Good luck
Ivar
Hi have you checked that your discretisation is high enough to get a non zero derivatives? Depending on which "dependent variable" you have you can only derive 2x in standard 2md order discretization, and you wil get step funtions, you need to get higher discrtisation to get smoother or higher derivatives. And several physics in the ACDC domain you work already by default on the derivative of the true solved varable field -- Good luck Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jul 26, 2012, 6:13 a.m. EDT
Hi

I'm using Comsol 4.2 to solve the Laplace equation for a 2D geometry with 2 sets of boundary conditions. I've obtained the 2d plots for the shape of the potential in the case of the 2 sets of boundary conditions. The solutions are named by default u and u2 (I've used Laplace eq separately for the 2 sets).
Now I want to create a 2d plot surface using the 2 solutions from above. The expression that I want to use for my plot is:

log(grad(|grad(u)|^2+|grad(u2)|^2))

if I use only the expression |grad(u)|^2+|grad(u2)|^2=abs(uxx+uyy)^2+abs(u2xx+u2yy)^2 the plot gives me a nonzero value. But if I try to differentiate the expression |grad(u)|^2+|grad(u2)|^2 the plot gives me zero everywhere.
I've tried to use the operators d(f,x) and pd(f,x) in the definition of my expression but the result is always zero.

Could someone help me please!
thanks

Ciprian
Hi I'm using Comsol 4.2 to solve the Laplace equation for a 2D geometry with 2 sets of boundary conditions. I've obtained the 2d plots for the shape of the potential in the case of the 2 sets of boundary conditions. The solutions are named by default u and u2 (I've used Laplace eq separately for the 2 sets). Now I want to create a 2d plot surface using the 2 solutions from above. The expression that I want to use for my plot is: log(grad(|grad(u)|^2+|grad(u2)|^2)) if I use only the expression |grad(u)|^2+|grad(u2)|^2=abs(uxx+uyy)^2+abs(u2xx+u2yy)^2 the plot gives me a nonzero value. But if I try to differentiate the expression |grad(u)|^2+|grad(u2)|^2 the plot gives me zero everywhere. I've tried to use the operators d(f,x) and pd(f,x) in the definition of my expression but the result is always zero. Could someone help me please! thanks Ciprian

Ivar KJELBERG COMSOL Multiphysics(r) fan, retired, former "Senior Expert" at CSEM SA (CH)

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jul 26, 2012, 5:20 p.m. EDT
Hi

I do not really follow you, for me uxx is the second derivative of the dependent variable u, but grad(u) should be based on the first derivative, no ?

And probably the d() operator has an issue with the abs() function that is not derivable for an argument aroud "0"

--
Good luck
Ivar
Hi I do not really follow you, for me uxx is the second derivative of the dependent variable u, but grad(u) should be based on the first derivative, no ? And probably the d() operator has an issue with the abs() function that is not derivable for an argument aroud "0" -- Good luck Ivar

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Jul 26, 2012, 6:51 p.m. EDT
Hi

In the end I've figured out, after many trials, what was the problem.
Now my plots are not empty anymore :)

Ivar you are wright..one problem was that I've used uxx instead of ux for the definition of grad(u)..I've noticed that almost immediately after posting my comment on the forum. and the other problem was with the correct definition of the function

Ciprian
Hi In the end I've figured out, after many trials, what was the problem. Now my plots are not empty anymore :) Ivar you are wright..one problem was that I've used uxx instead of ux for the definition of grad(u)..I've noticed that almost immediately after posting my comment on the forum. and the other problem was with the correct definition of the function Ciprian

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Sep 5, 2012, 1:15 a.m. EDT

Hi Ciprian,
How did you solve the problem with zero partial differentiating of the electric field. I have the same problem. I am using pd(es.Ez,z) or pd(es.normE,z) . Neither of them gives me nonzero plot. Besides, I would like to define a parameter as Ezz, for instance and export it in MATLAB via matlab livelink. I would appreciate if you could help me out.
Thanks,
Elham





Hi

In the end I've figured out, after many trials, what was the problem.
Now my plots are not empty anymore :)

Ivar you are wright..one problem was that I've used uxx instead of ux for the definition of grad(u)..I've noticed that almost immediately after posting my comment on the forum. and the other problem was with the correct definition of the function

Ciprian


Hi Ciprian, How did you solve the problem with zero partial differentiating of the electric field. I have the same problem. I am using pd(es.Ez,z) or pd(es.normE,z) . Neither of them gives me nonzero plot. Besides, I would like to define a parameter as Ezz, for instance and export it in MATLAB via matlab livelink. I would appreciate if you could help me out. Thanks, Elham [QUOTE] Hi In the end I've figured out, after many trials, what was the problem. Now my plots are not empty anymore :) Ivar you are wright..one problem was that I've used uxx instead of ux for the definition of grad(u)..I've noticed that almost immediately after posting my comment on the forum. and the other problem was with the correct definition of the function Ciprian [/QUOTE]

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Sep 5, 2012, 4:25 a.m. EDT
Hi Elham,

I've used the function d(expresion,x)...in your case it would be d(ec.Ez,z)..but probably this is not why your plots are empty.
I don't know what problem are you trying to solve..but in my case I was solving the Laplace equation..and the unknown (i.e the potential)it was given the implicit name u by Comsol. Then I've used that variable for my plots. one of the plot was of the form:
log10(sqrt(ux^2+uy^2)) and I've got a nonzero plot.

I recommend you to build you expressions for the plots using the implicit names given to your variables by Comsol.
You could also have zero plots because your boundary condition for the problem are not the right ones..you should also check that.
Regarding haw to export an expresion in Matlab form Comsol I'm afraid that I can't help you..I've never used that function of comsol so far.

Ciprian
Hi Elham, I've used the function d(expresion,x)...in your case it would be d(ec.Ez,z)..but probably this is not why your plots are empty. I don't know what problem are you trying to solve..but in my case I was solving the Laplace equation..and the unknown (i.e the potential)it was given the implicit name u by Comsol. Then I've used that variable for my plots. one of the plot was of the form: log10(sqrt(ux^2+uy^2)) and I've got a nonzero plot. I recommend you to build you expressions for the plots using the implicit names given to your variables by Comsol. You could also have zero plots because your boundary condition for the problem are not the right ones..you should also check that. Regarding haw to export an expresion in Matlab form Comsol I'm afraid that I can't help you..I've never used that function of comsol so far. Ciprian

Please login with a confirmed email address before reporting spam

Posted: 1 decade ago Mar 19, 2014, 2:10 p.m. EDT
That is ok if you are looking for a variable which is already built-in in COMSOL, e.g. Ex=-d(V,x). Although, I am trying to get the first derivative of carrier concentrations on the semiconductor module d(semi.N,x) or d(semi.P,x) and I get zeros. I tried to different mesh grids, even very very dense.

--
Alessia Polemi
That is ok if you are looking for a variable which is already built-in in COMSOL, e.g. Ex=-d(V,x). Although, I am trying to get the first derivative of carrier concentrations on the semiconductor module d(semi.N,x) or d(semi.P,x) and I get zeros. I tried to different mesh grids, even very very dense. -- Alessia Polemi

Please login with a confirmed email address before reporting spam

Posted: 8 years ago Oct 12, 2016, 12:56 a.m. EDT
Hi all,

I am also facing the same problem. I need to evaluate d(log(p/patm),rho) but it is returning zero value. rho is a dependent variable which I am specifying through a user defined general pde.
Any suggestions?

Thanks
Mahvash
Hi all, I am also facing the same problem. I need to evaluate d(log(p/patm),rho) but it is returning zero value. rho is a dependent variable which I am specifying through a user defined general pde. Any suggestions? Thanks Mahvash

Jeff Hiller COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 8 years ago Oct 12, 2016, 9:44 a.m. EDT
There are various cases where taking a derivative will give you uniformly zero - typically because the interpolation in each element of the quantity the derivative of which you are trying to plot is constant.
See www.comsol.com/blogs/plotting-spatial-derivatives-magnetic-field/ for a way to get the plot you are after by mapping the solution onto a higher order mesh.
Best,
Jeff
There are various cases where taking a derivative will give you uniformly zero - typically because the interpolation in each element of the quantity the derivative of which you are trying to plot is constant. See https://www.comsol.com/blogs/plotting-spatial-derivatives-magnetic-field/ for a way to get the plot you are after by mapping the solution onto a higher order mesh. Best, Jeff

Note that while COMSOL employees may participate in the discussion forum, COMSOL® software users who are on-subscription should submit their questions via the Support Center for a more comprehensive response from the Technical Support team.