0
$\begingroup$

I have this equation and I need to solve it analytically by Mathematica https://i.stack.imgur.com/fCnxk.png enter image description here

I tried the following

k = 32;
eqn = {(u^\[Prime]\[Prime])[x] == Piecewise[{{1/2 k^2 Cos[2 \[Pi] k x], 0 <= x < 0.1}, {( k^2 Cos[2 \[Pi] k x])/1.5, 0.1 <= x < 0.2}, {(
  k^2 Cos[2 \[Pi] k x])/0.75, 0.2 <= x < 0.3}, {(
  k^2 Cos[2 \[Pi] k x])/1.5, 0.3 <= x < 0.4}, {(
  k^2 Cos[2 \[Pi] k x])/3.75, 0.4 <= x < 0.5}, {(
  k^2 Cos[2 \[Pi] k x])/0.75, 0.5 <= x < 0.6}, {(
  k^2 Cos[2 \[Pi] k x])/1.25, 0.6 <= x < 0.7}, {(
  k^2 Cos[2 \[Pi] k x])/0.75, 
  0.7 <= x < 0.8}, {1/2 k^2 Cos[2 \[Pi] k x], 
  0.8 <= x < 0.9}, {k^2 Cos[2 \[Pi] k x], 0.9 <= x < 1}}], 
  u[0] == 0.1, u[1] == 0.2}

sol = DSolve[eqn, u[x], x]
$\endgroup$
  • $\begingroup$ What have you tried? $\endgroup$ – corey979 Apr 8 '18 at 22:09
  • $\begingroup$ I am sorry I am new to this forum so how can I add my code properly $\endgroup$ – Amr Saleh Apr 8 '18 at 22:17
  • $\begingroup$ I added my code $\endgroup$ – Amr Saleh Apr 8 '18 at 22:25
2
$\begingroup$

You simply need to enter the \[Prime]s without ^, that means

k = 32;
eqn = {(u'')[x] == 
   Rationalize[Piecewise[{{1/2 k^2 Cos[2 π k x], 
      0 <= x < 0.1}, {(k^2 Cos[2 π k x])/1.5, 
      0.1 <= x < 0.2}, {(k^2 Cos[2 π k x])/0.75, 
      0.2 <= x < 0.3}, {(k^2 Cos[2 π k x])/1.5, 
      0.3 <= x < 0.4}, {(k^2 Cos[2 π k x])/3.75, 
      0.4 <= x < 0.5}, {(k^2 Cos[2 π k x])/0.75, 
      0.5 <= x < 0.6}, {(k^2 Cos[2 π k x])/1.25, 
      0.6 <= x < 0.7}, {(k^2 Cos[2 π k x])/0.75, 
      0.7 <= x < 0.8}, {1/2 k^2 Cos[2 π k x], 
      0.8 <= x < 0.9}, {k^2 Cos[2 π k x], 0.9 <= x < 1}}], 
  u[0] == 0.1, u[1] == 0.2}]
sol = DSolve[eqn, u[x], x];

Plot[Evaluate[PiecewiseExpand[u[x] /. sol[[1]]]], {x, 0, 1}]

enter image description here

Rationalize converts this to exact numbers, in order to make it easier for DSolve.

|improve this answer|||||
$\endgroup$
  • $\begingroup$ I got this plot but when I solved it using finite element I got a different plot. I compared it to my friend solution by matlab. I found this plot is not the same but the finite element one is correct $\endgroup$ – Amr Saleh Apr 8 '18 at 22:43
  • $\begingroup$ How did you validate that? With these high oscillations, you need quite fine elements in order to reproduce the wiggles with FEM. D[PiecewiseExpand[u[x] /. sol[[1]]], x, x] returns the right hand side exactly and satisfies also the boundary conditions. $\endgroup$ – Henrik Schumacher Apr 8 '18 at 22:50
  • $\begingroup$ I validated it with my friend I used 10000 elements to be fine enough. you are correct I also did that and the solution returns the right hand side $\endgroup$ – Amr Saleh Apr 8 '18 at 22:55
  • 1
    $\begingroup$ Ah, now I see it: Your strong formulation is wrong. You have to apply the product rule as $A_1$ is not a constant function: It is piecewise constant, thus its derivative is a linear combinations of Dirac distributions. So you get also term of the form $A_1'(t) \, u'(t) = -\sum_i \delta_{t_i}(t) \, u'(t)$. You may use DiracDelta for formulating this. $\endgroup$ – Henrik Schumacher Apr 8 '18 at 23:00
  • $\begingroup$ I got your idea but I want to ask what is the value i $\endgroup$ – Amr Saleh Apr 9 '18 at 0:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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