pde – Solving the Cauchy problem for the wave equation using Neumann boundary conditions

I've been trying to solve this problem for a while, but I can't seem to figure out what to do with the Neumann Limit Condition. The problem is solving the following:

begin {equation *}
u_ {tt} -u_ {xx} = 0 \
u (x, 0) = 0 \
u_t (x, 0) = begin {cases}
pi cos ( pi (x-1)), y 1 <x <2 \
0 and more
end {cases}
end {equation *}

For the next
1) $$ x in (- infty, infty) $$
two) $$ x in (0, infty) text {y} u_x (0, t) = 0 $$
3) $$ x in (- infty, 3) text {y} u (3, t) = 0 $$

I know how to do 1, just apply D & # 39; Alemebert's formula. But I am lost by 2 and 3.

equation solving: set of multivariable expressions to re-express a single variable

I have a set of expressions like $ frac {3x + y-z} {6x} $ Y $ frac {3 x-y + z} {12 x} $, which can be easily re-expressed as $ p $ Y $ (1-p) / 2 $, where $ p = frac {3x + y-z} {6x} $, but is there any way to find this? $ p $, not manually? I mean: how do I find a $ p $ so that each expression can be expressed solely as a function of $ p $ in Mathematica? (I to know it is true to find such $ p $ for a given set, I just can't find it computationally)

equation solving – Vectorized rootFind for interpolated function

I spent the last few days trying to vectorize my code to speed up root search on a grid. Sorry in advance if my code is badly formatted. I have a good amount of configuration for the problem. It really starts from here, where I solve a great system of equations and find an interpolated trcfnint function:

Clear("`*");
E2H(E_, c_) := 1/(c^2 - 1) (E)
E2H1 = Compile({{E, _Real}, {c, _Real}}, 1/(c^2 - 1) (E))
c = 1.1
E1 = 0.5
H = E2H1(E1, c)
If(c < 1 , 
  period = Abs(
    2 NIntegrate(
      1/Sqrt(2 H - 1/(c^2 - 1) (u^4/2 - u^2)), {u, -Sqrt(
         1 - Sqrt(1 + 4 (c^2 - 1) H)), 
       Sqrt(1 - Sqrt(1 + 4 (c^2 - 1) H))})), 
  period = Abs(
    2 NIntegrate(
      1/Sqrt(2 H - 1/(c^2 - 1) (u^4/2 - u^2)), {u, -Sqrt(
         1 + Sqrt(1 + 4 (c^2 - 1) H)), 
       Sqrt(1 + Sqrt(1 + 4 (c^2 - 1) H))})));
sgtwv = NDSolveValue({(c^2 - 1) u2''(t) + u2(t)^3 - u2(t) == 0, 
    u2(0) == 0, u2'(0) ==  Sqrt(2 H) },
   u2, {t, 0, 50});
grid = Table(a + I b, {a, -1, 1, 0.02}, {b, -1, 1, 0.02});
gvals = Riffle(Flatten(grid), Flatten(grid));
A(t_) := SparseArray(
  Flatten(Table({{2 j - 1, 2 j} -> 
      1, {2 j, 
       2 j - 1} -> -1/(c^2 - 1) (gvals((j))^2/(c^2 - 1) + 
         3 sgtwv(t)^2 - 1)}, {j, Length(gvals)}), 1))
initialc = 
  Table(If(Mod(i, 4) == 1 || Mod(i, 4) == 0, 1, 0), {i, 
    2 Length(gvals)});
ff = NDSolveValue({q'(t) == A(t).q(t), q(0) == initialc}, {q}, {t, 0, 
     3 period}); // AbsoluteTiming
ggg = Flatten(Through(ff(period)));
trc = ggg((1 ;; -1 ;; 4)) + ggg((4 ;; -1 ;; 4));
listint = ArrayReshape(trc, Dimensions(grid));
trcfnint = ListInterpolation(listint, {{-1, 1}, {-1, 1}})
evs1(a_?VectorQ, b_?VectorQ, d_?VectorQ) := 
  trcfnint(a, b) - 2 Cos(c period (a + I b)/(c^2 - 1) + d);
evs2(a_, b_, d_) := 
  trcfnint(a, b) - 2 Cos(c period (a + I b)/(c^2 - 1) + d);

My goal is to find (a, b, d) in the interpolated range so that evs2 is 0 (evs1 it's just the vectorized version). This is very fast and easy when b = 0:

imAxis1 = {}; Do(
 plot1 = Plot(
   trcfnint(a, 0) - 2 Cos(c period a/(c^2 - 1) + (Theta)), {a, 0, 1},
    Mesh -> {{0}}, MeshFunctions -> {#2 &}, 
   MeshStyle -> PointSize(Medium), PlotRange -> {{0, 1}, {0, 0}}, 
   PlotPoints -> 100); 
 AppendTo(imAxis1, 
  Sort@Cases(Normal@plot1, Point({x_, y_}) -> x, 
    Infinity)), {(Theta), 0, 2 Pi + 0.1, 0.01});
imAxis1 = Flatten(imAxis1); imAxis1 = 
 Transpose({ConstantArray(0, Length(imAxis1)), imAxis1});
ListPlot(imAxis1, PlotStyle -> Directive(Red, PointSize(0.005)), 
 PlotRange -> {{-1, 1}, {-1, 1}}, 
 FrameLabel -> {Style("Re((Lambda))", FontSize -> 20), 
   Style("Im((Lambda))", FontSize -> 20)}, 
 LabelStyle -> Directive(Black), ImageSize -> Large, AspectRatio -> 1,
  Frame -> True, Axes -> False)

When b != 0, the most reliable results I have are using the non-vectorized function evs2 in the following code:

total = {};
Table(Do(
    root1 = 
     FindRoot({Re(evs2(aa, b, dd)) == 0, 
       Im(evs2(aa, b, dd)) == 0}, {{aa, a}, {dd, theta}}, 
      MaxIterations -> 20, AccuracyGoal -> 6);
     test = Abs(evs2(aa, b, dd)) /. root1;
    If(Abs(test) < 10^(-5), AppendTo(total, {b, root1((1))((2))}));
    Break, {theta, 0, 2 Pi, 2}), {a, {0.5, 0.6}}, {b, 0, 0.18, 
    0.001}); // AbsoluteTiming
ListPlot(total, PlotStyle -> Directive(Red, PointSize(0.005)), 
 PlotRange -> {{-1, 1}, {-1, 1}}, 
 FrameLabel -> {Style("Re((Lambda))", FontSize -> 20), 
   Style("Im((Lambda))", FontSize -> 20)}, 
 LabelStyle -> Directive(Black), ImageSize -> Large, AspectRatio -> 1,
  Frame -> True, Axes -> False)

When executing this, I only take the top half bubble. The initial values ​​for a are chosen because they are in a spectral space on the axis a and this saves a lot of time in the calculations. In general, I would like to have the ability to quickly solve many values ​​of a. I've examined several different questions about this vectorization: Findroot with a precompiled function with parameters, Jacobian for FindRoot in parallel with multiple variables, FindRoot with vector functions were the most useful. I can publish my successful vectorizations, however they suffer being slower than the non-vectorized implementation. If anyone has any advice I would greatly appreciate it.

algorithms – NP problem solving: analogy between the SAT problem and the shortest path problem

in this 2 minute video https://www.youtube.com/watch?v=TJ49N6WvT8M (excerpted from a free udacity course on algorithms / theoretical computer science),

whose purpose is to show how a SAT problem can be solved as it would be the shortest path problem,

I understand that

  • exist n route patterns like n different boolean variables that belong to a "AND group of clauses "." Clause "be" a OR group "made up of conditions on some of the n variables

    example: of a SAT problem being "find values ​​of x1, x2, x3 such that clause1 AND clause2 AND clause3 It is true", being clause1 x1 OR x2 (it is true), being clause 2 x1 OR NOT(x3)etc.
  • m vertices added to force the m clauses to be ensured by having a unique "local" shortest path (within a local pattern)

But What I do not understand that's why every pattern has to have 3(m+1) vertices? Why are 2 diamonds per pattern not enough?

Thanks for enlightening me

solving equations – Problem simulating FindRoot

I am writing a procedure that simulates the findRoot built-in function using the same code that appears in Chapter 6 of $ textit {Math programming} $ by Paul Wellin. the code is the following.

findRoot[expr_, {var_, init_}, [Epsilon]_] :=
 Module[{xi = init, fun = Function[fvar, expr]},
  While[Abs[fun[xi]] > [Epsilon],
   xi = N[xi - fun[xi]/fun'[xi]]];
  {var -> xi}]

In the text, the code is successfully tested, but when I test it it doesn't work. For example,

In[5]:= findRoot[x^2 - 2, {x, 2.0}, 0.0001]

Out[5]= {x -> 2.}

I tried to change the variable fvar to var, and the program works, but this is a reuse of names that makes Mathica color the variable var red.

findRoot[expr_ == val_, {var_, init_}, [Epsilon]_] :=
 Module[{xi = init, fun = Function[var, expr - val]},
  While[Abs[fun[xi]] > [Epsilon],
   xi = N[xi - fun[xi]/fun'[xi]]];
  {var -> xi}]

I need some suggestion to clarify this problem.

Equation solving and verification program!

Move the equation 2x ^ 2 + 5x + 1 = 0 in the range of real numbers.

Then putting it in the equation, check if that is correct.

(Use NSlove, Chop and substitution)

I want a code that uses the above three operations … help me!

eigenvalues: different results when solving a system of equations analytically and numerically

I have the following system of differential equations:

begin {pmatrix} dfrac {d eta} {dt} \ dfrac {d eta ^ { dagger}} {dt} end {pmatrix} = begin {pmatrix} (1 + I kappa) (w-IJ) & R_1 + i R_1 kappa \ – R_1 + IR_1 kappa & (IJ + w) (- 1 + i kappa) \ end {pmatrix} begin {pmatrix} eta \ eta ^ { dagger} end {pmatrix}

To solve this system, I diagonalize the intermediate matrix and write the solution in terms of the normal modes. In Mathematica:

s = {{(1 + I (Kappa)) (w - I J), R1 + I R1 (Kappa)}, {-R1 +  I R1 (Kappa), -(1 - I (Kappa)) (w + I J)}};
{vals, vecs} = FullSimplify(Eigensystem(s ));
NormVector = Transpose(Normalize /@ vecs);
NormalModes = {{C1*Exp(I*vals((1))*t)}, {C1*Exp(I*vals((2))*t)}};
Solution = NormVector.NormalModes /. {w -> 0.27, (Kappa) -> 0.01, R1 -> 0.0025,
J -> 0.005}

In this case
$ Solution = left ( begin {array} {c}
(-0.00462882-0.0000462882 i) text {C1} e ^ {(0.0023 , -0.270038 i) t} – (0.999939 , +0.00999939 i)
text {CC1} e ^ {(0.0023 , +0.270038 i) t} \
0.999989 text {C1} e ^ {(0.0023 , -0.270038 i) t} +0.00462905 text {CC1} e ^ {(0.0023 , +0.270038 i) t}
\
end {array}
right) $

On the other hand, I define the constants before doing the calculation, in this way,

(Kappa) = 0.01
R1 = 0.025;
J = 0.005;
w = 0.27;
  s = {{(1 + I (Kappa)) (w - I J), R1 + I R1 (Kappa)}, {-R1 +  I R1 (Kappa), -(1 - I (Kappa)) (w + I J)}};
{vals, vecs} = FullSimplify(Eigensystem(s ));
NormVector = Transpose(Normalize /@ vecs);
NormalModes = {{C1*Exp(I*vals((1))*t)}, {C1*Exp(I*vals((2))*t)}};
Solution2 = NormVector.NormalModes /. {w -> 0.27, (Kappa) -> 0.01, R1 -> 0.0025,
J -> 0.005}

In this case $ Solution2 = left ( begin {array} {c}
(0.998926 , +0. I) text {CC1} e ^ {(0.0023 , +0.26889 i) t} – (0.0463375 , +0.000463375 i) text {C1}
e ^ {(0.0023 , -0.26889 i) t} \
(0.998926 , +0. I) text {C1} e ^ {(0.0023 , -0.26889 i) t} + (- 0.0463375 + 0.000463375 i) text {CC1}
e ^ {(0.0023 , +0.26889 i) t} \
end {array}
right) $

That is the correct result, I don't understand why I get different results. In the first solution, the imaginary part of the second row of the matrix is ​​missing.

Thank you

parametric functions – Problem: solving the system of equations

I am trying to solve a "simple" system of equations for a formal theoretical model that I am developing. Although I think I had correctly specified the system, I can't find a solution so far. Is it a problem with so many parameters? Can someone help me with this?

Solve({A1*A2*y - A3*y - A4 - A5*((1/A6)^(1-A7))*((x*A8 + A9)^(A10)) + A11*((A6)^(-A12))*((y*A13)^(A14)) == 0, A15*A16*x - A17*x -A19 - A18*A6+ A5*((1/A6)^(1-A7))*((x*A8 + A9)^(A10)) - A11*((A6)^(-A12))*((y*A13)^(A14)) == 0, 00, A2>0,A3>0,A4>0,A5>0,A6>0,A7>0,A8>0,A9>0,A10>0,A11>0,A12>0,A13>0,A14>0,A15>0,A16>0,A17>0, A18>0, A19>0}, {x,y})

Thank you!

solving an exercise

"Ask the user to enter 5 numbers in a text box. Check what the largest number is and show it."

I thought when I wrote the space for it to take the number, how can I do it without multiple entries?

equation solving: assign the results of a resolution to variables

Ah, they finally implemented it in version 10, then!
Here is a procedure that I have been using since version 5, it could provide similar features in versions prior to the introduction of Value.
(I'm not sure, but maybe I posted it on MathGroup … so forgive me if this is not news)

I called it "ToValues". I gave him two options:

Options(ToValues) = {
      Flattening -> Automatic, IndexedFunction -> False};

Hopefully the help message is self explanatory:

ToValues::usage =
    "ToValues(li) 
    suppresses the Rule wrapper in every part of list li.n ToValues(li,F) 
applies the function F to every rhs of Rule, turning var->value into 
F(value). If the function F has a parametrized head, then it is possible to 
pass the lhs of Rule to it by setting the option IndexedFunction->True. It will 
turn var->value into F(var)(value).n When the option Flattening is set to 
Automatic, ToValues flattens li to yield a simplified structure (the 
flattening is tuned to get the simplest list of values for the solution of a 
system of several equation in several variables). With Flattening set to None 
the original structure is left intact.";

The code is really short.

ToValues(li_, opts___Rule) := Module(
    {newli, vars, sols, fl},
    fl = Flattening /. {opts} /. Options(ToValues);
    sols = First(Dimensions(li)); vars = Last(Dimensions(li));
    newli = li /. Rule(_, v_) -> v;
    If(fl == Automatic && vars == 1, newli = Flatten(newli));
    If(fl == Automatic && sols == 1, First(newli), newli)
    )

ToValues(li_, fun_, opts___Rule) := 
  Module(
    {newli, vars, sols, foo, fl, mi},
    mi = IndexedFunction /. {opts} /. Options(ToValues);
    fl = Flattening /. {opts} /. Options(ToValues);
    If(mi == True,
          newli = li /. (x_ -> v_) -> foo(x)(v),
          newli = li /. (_ -> v_) -> foo(v)
      );
    sols = First(Dimensions(li)); vars = Last(Dimensions(li));
    If(fl == Automatic && vars == 1, newli = Flatten(newli));
    If(fl == Automatic && sols == 1, First(newli), newli) //. foo -> fun
)

Sample data:

sols = {{x -> 1}, {y -> 2}, {z -> 3}};

Applying ToValues ​​to rule lists produces a list of values

ToValues(sols) // InputForm

{1, 2, 3}

Of course, the assignment is immediate, here

{x1,x2,x3} = ToValues(sols)

By default, ToValues ​​returns the simplest possible list of values, deleting the nested list. If you want to keep the original nesting, this is what the Docking option does:

ToValues(sols, Flattening -> None) // InputForm

{{1}, {2}, {3}}

We can specify a function to apply to the return values.

ToValues(sols, F) // InputForm

{F (1), F (2), F (3)}

We can also use functions that make use of the right sides of the rules. Just define them as functions with a parameterized Head and set IndexedFunction-> True to tell ToValues ​​to use that. In this case, we want to return lists in the form {variable name, variable value}:

F(var_)(value_) := {var, value}

ToValues(sols, F, IndexedFunction -> True) // InputForm

{{x, 1}, {y, 2}, {z, 3}}

ToValues(sols, F, IndexedFunction -> True, Flattening -> None) // InputForm

{{{x, 1}}, {{y, 2}}, {{z, 3}}}

Real world applications

ToValues ​​is normally used to extract solutions from the lists returned by Solve, NSolve, DSolve, etc. In its default form, it can be applied like this:

Solve({x + y == 1, x - y == 2}) // ToValues

{3/2, 1/2}

This provides a list of complex solutions.

Solve(x^5 == 1) // ToValues

Use the optional function to calculate the real and imaginary part of each solution.

coords = ToValues(Solve(x^5 == 1, x), {Re(#), Im(#)} &) // N;
ListPlot(coords, AspectRatio -> Automatic, Frame -> True, 
   PlotStyle -> PointSize(.018));

And this pushes the function to create graphic objects (Points) based on those values ​​inside ToValues:

pts = ToValues(Solve(x^9 == 1, x), Point({Re(#), Im(#)}) &);
Show(Graphics({PointSize(.018), pts}),
    AspectRatio -> 1, Frame -> True, Axes -> True);

Someone with enough patience might want to add the frames.