1
$\begingroup$

I have the function fun[x_,y_, t_] = Cos[x] + Exp[I y] Sin[x] Sin[t]; such that $0\le {\rm x}\le \pi$, $0\le {\rm y}\le 2\pi$, and $0\le {\rm t} \le 10$. I compute the derivative of the real part of this function as derivativefun[x_,y_, t_] = D[Re[fun[x,y, t]], t];. Now I want to write the following algorithm to be executed on Mathematica:

Step1: Select a value of x and y say x=0 and y=0, find derivativefun[0,0, t]; Integrate over those intervals of t for which derivativefun[0,0, t] is positive (The integral will be a function of t).

Step2: Select another value of x and y say x=0.5 and y=0.5 find derivativefun[0.5,0.5, t];Integrate over those intervals of t for which derivativefun[0.5,0.5, t] is positive (again, the integral will be a function of t).

Step3: Do the same for the entire range of $0\le {\rm x} \le\pi$ and $0\le {\rm y} \le 2\pi$.

Step4: Finally, choose that integral (as a function of t) which is the maximum of all.

To sum up, I need to compute the integral of the derivative of the real part of fun[x_,y_, t_]over the range of ${\rm t}$ where the derivative is an increasing function. This is to be done for all values of parameters ${\rm x}$ and ${\rm y}$ within their given ranges. Finally that integral is to be chosen which is the maximum of all.

Edit: The derivative is to be taken of the absolute value of the function fun[x_,y_, t_].

Edit2: Since there are issues with the derivative of the Abs[]. It turns out that real part of the function fun[x_,y_, t_] would also work for me. Therefore, I have edited the question, changing Abs[] to Re[].

$\endgroup$
2
  • $\begingroup$ Your function is complex, so what does it mean to integrate over the intervals where the function is positive? Also, what have you tried? $\endgroup$
    – Carl Woll
    May 16, 2019 at 17:05
  • $\begingroup$ Thanks, @CarlWoll. It should be the absolute value of the derivative of function. Edited my question. $\endgroup$
    – H. Kenan
    May 17, 2019 at 4:44

1 Answer 1

3
$\begingroup$

The definition of derivativefun[x_,y_, t_] = D[Abs[fun[x,y, t]], t]; seems to be wrong, because t is used as function argument and as variable of differentiation.

Try (avoid use of Abs[] because Abs'[] isn't defined)

derivativefun[x_, y_ ] :=Evaluate[ComplexExpand[D[Sqrt[# Conjugate[#]] &[ fun[x, y, t]], t]]];

which gives what you want

Plot[derivativefun[1, 0]  , {t, 0, 10}]

enter image description here

The integration (for examplary x,y ) over positive derivative follows to

NIntegrate[ Max[0, derivativefun[1, 0] ], {t, 0, 10}]
(*2.52441*)

addendum

The question changed from Abs to Re, which simplifies the problem considerably.

real part of fun[x_, y_, t_]

D[ComplexExpand[Re[Cos[x] + Exp[I y] Sin[x] Sin[t]], TargetFunctions -> {Re, Im}], t]
(*Cos[t] Cos[y] Sin[x]*)

f[x_, y_] := NIntegrate[Max[0, Cos[t] Cos[y] Sin[x]], {t, 0,10}]
Plot3D[f[x, y], {x, 0, Pi}, {y, 0, 2 Pi}]

enter image description here

The maximum of this surface is waht you are looking for!

$\endgroup$
12
  • $\begingroup$ Thanks, @Ulrich Neumann. It turns out that Re[] would equally work for my problem. Therefore, I have edited the question, replacing Abs[] by Re[]. $\endgroup$
    – H. Kenan
    May 17, 2019 at 7:20
  • $\begingroup$ That simplifies the problem considerably! $\endgroup$ May 17, 2019 at 7:37
  • $\begingroup$ Thanks, @Ulrich Neumann. That looks good. However, I want just a 2-D plot, which shows the Integral (for a particular x=x_0 and y=y_0) as a function of t, such that this integral is the maximum from all other integrals (wich are for other values of x and y). $\endgroup$
    – H. Kenan
    May 17, 2019 at 9:34
  • $\begingroup$ After integrating over t there is no dependancy on t anymore! The value of this integral is plotted in my answer. $\endgroup$ May 17, 2019 at 9:37
  • $\begingroup$ Can't one talk about the indefinite integral here? I mean without giving limits? $\endgroup$
    – H. Kenan
    May 17, 2019 at 10:02

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.