0
$\begingroup$

I wold like to know how to get a function from a numerical integration. Here is an example:

h[y_?NumericQ] := NIntegrate[y*Sin[Sin[x]], {x, 1, 2}]
h[2]

Then my output will be 1.6329, but I'm looking for a way to get a function of y, with no need to give a numerical value to the variable. In this case my function should be:

h[y_]=0.81645*y

That is an easy example. Actually I have the following situation:

E1=200000;
t=2;
v=0.3;
phi=1
Dp = (E1*t^3)/(12*(1 - v^2));
j1 = 2;
Do[w[m1, n1] = ToExpression["w" <> ToString[m1] <> ToString[n1]], {m1,
    1, j1}, {n1, 1, j1}];
disp[x_, y_, w11_, w12_, w21_, w22_] = 
  Sum[Sum[w[m1, n1]*Sin[m1*(Pi*x/a + Pi/2)]*
     Sin[n1*(Pi*y/b + Pi/2)], {n1, 1, j1}], {m1, 1, j1}];
U[w11_, w12_, w21_, w22_] = ((Dp*a*b*Pi^4)/(8*a^4))*
   Sum[Sum[(w[m1, n1]^2*(m1^2 + phi^2*n1^2)^2), {n1, 1, 
      j1}], {m1, 1, j1}];
V1[Ny_?NumericQ, w11_?NumericQ, w12_?NumericQ, w21_?NumericQ, 
  w22_?NumericQ] := (-t/2)*
  NIntegrate[
   NIntegrate[
    Evaluate[
      N1[Ny, x, y]]*(D[disp[x, y, w11, w12, w21, w22], x])^2, {x, -b/
      2, b/2}], {y, -a/2, a/2}]
V2[Ny_?NumericQ, w11_?NumericQ, w12_?NumericQ, w21_?NumericQ, 
  w22_?NumericQ] := (-t/2)*
  NIntegrate[
   NIntegrate[
    Evaluate[
      N2[Ny, x, y]]*(D[disp[x, y, w11, w12, w21, w22], y])^2, {x, -b/
      2, b/2}], {y, -a/2, a/2}]
V3[Ny_?NumericQ, w11_?NumericQ, w12_?NumericQ, w21_?NumericQ, 
  w22_?NumericQ] := (-t)*
  NIntegrate[
   NIntegrate[
    Evaluate[
      T3[Ny, x, y]]*(D[disp[x, y, w11, w12, w21, w22], x])*(D[
       disp[x, y, w11, w12, w21, w22], y]), {x, -b/2, b/2}], {y, -a/2,
     a/2}]

The functions N1, N2 and T3 come from another notebook and are working well. The point is, I need to derive the sum of functions U, V1, V2 and V3 in relation to w11, then I must derive the same sum in relation to w22, and so on. In the end, these resulting functions must be organized in a matrix.

$\endgroup$
3
  • 1
    $\begingroup$ Integrate[]? -- You say it's difficult (well, complex), but difficult situations often need solutions tailored to the situation. Without a representative example, it's hard to say. $\endgroup$
    – Michael E2
    Mar 15, 2020 at 22:04
  • 1
    $\begingroup$ how to get a function from a numerical integration you can't. As Michael says, you need to try Integrate. But sin(sin(x)) is really hard to integrate analytically. $\endgroup$
    – Nasser
    Mar 15, 2020 at 22:07
  • 1
    $\begingroup$ @user70148, i think you simply forgot to set values for a and b. With that your code should work. (Of course i don't know if the N1,N2, T 3 are friendly) $\endgroup$
    – Akku14
    Dec 11, 2020 at 8:10

1 Answer 1

1
$\begingroup$

Ok, as far as I see you need to interpolate. For your simple example:

 h[y_?NumericQ] := NIntegrate[y*Sin[Sin[x]], {x, 1, 2}]
 h1 = Interpolation[Table[{y, h[y]}, {y, 1, 10, .01}], 
      Method -> "Spline", InterpolationOrder -> 2]
 h[2]==h1[2]
 (*True*)

h1 is your function

$\endgroup$
3
  • $\begingroup$ I think it worked, but what did you exactly did? What means the {y, 1, 10, .01}? And what if I have 2 or more variables? $\endgroup$
    – user70148
    Mar 15, 2020 at 23:27
  • 1
    $\begingroup$ Please check mathematica.stackexchange.com/questions/18210/… $\endgroup$
    – Rupesh
    Mar 15, 2020 at 23:29
  • 2
    $\begingroup$ @user70148 Why don't you simply c= NIntegrate[Sin[Sin[x]], {x, 1, 2}] followed by h[y_]:=c y ? $\endgroup$
    – yarchik
    Aug 8, 2021 at 11:36

Your Answer

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

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