I ma trying to solve this cubic equation for the variables a0,a1,a2,a3
ParametricNDSolve[{uz[t] == (a0[t]^3 + a1[t]^2 + a2[t] + a3),
uz[0] == 0, uz[T] == 1, uz'[] == 0, uz'[0] == 0}, {uz}, {t, 0,
T}, {a0, a1, a2, a3}];
but I am getting the following error in mathematica.
Dependent variables {a0,a1,a2} cannot depend on parameters {a0,a1,a2,a3}.
Which function to use in mathematica to solve the above parametric equation with the given initial conditions and get {a0, a1, a2, a3}
Related
I'm trying to use Mathematica to verify that the following function
V[x1_, x2_, u1_, u2_] = 1.494*u1^2 - 2.094 10^-24*u1 + 1.494*u2^2 - 3.988*u2 + 1.994*x2^2 - 7.333 10^-24*x2 + 2.494
is positive definite with constraint u1^2+u2^2==1.
Reduce[ForAll[{x1, x2, u1, u2}, u1^2 + u2^2 == 1, V[x1, x2, u1, u2] >= 0], {x1, x2, u1, u2}, Reals]
returns False. But searching for the counter-example
cex = FindInstance[u1^2 + u2^2 == 1 && V[x1, x2, u1, u2] < 0, {x1, x2, u1, u2}, Reals]
V[x1, x2, u1, u2] /. cex
gives
{{x1 -> 0.2, x2 -> 0, u1 -> 5.16988*10^-25, u2 -> 1.}}
{2.22045*10^-16}
So, Mathematica appears to contradict itself. What mistake am I making?
one approach here: make the expression exact. ( you should check i got this right )
exp=1494/1000*u1^2 - 2094 10^-27*u1 + 1494/1000*u2^2 - 3988/1000*u2 +
1994/1000*x2^2 - 7333 10^-27*x2 + 2494/1000
now we can find an exact minimum:
min = Minimize[{exp, u1^2 + u2^2 == 1}, {u1, u2, x2}] // Simplify //First
this is negative:
min<0
True
however it is a very small negative value:
N[min, 20]
-7.2915903961885656971*10^-48
My guess would be the original expression is constructed to have a zero minimum and the constants are not given to sufficient precision.
Example to make it zero the last constant needs to be
2.4940000000000000000000000000000000000000000000072915903961..
Although given that you have coefficients on the order 10^-24, maybe that is significant.
I'm new to Mathematica, and I'm trying to solve a matrix equation in a form as
AX = \lambda BX
Here, Aand B are 4*4 matrices in the following, \lambda is a value, Xis the eigenvector- 4*1 matrix.
A = {{a1 + b1, c, d, f},
{c, a2 + b2 , f , e},
{d , f , a3 + b1 , c},
{ f, e , c, a4 + b2}}
B = {{1, 0, 0 , 0},
{0, 1 , 0 , 0},
{0 , 0 , -1 , 0},
{0, 0 , 0, -1}}
I would like to solve this matrix equation and get the symbolical solution for \lambda using a1,a2,a3,a4,b1,b2,c,d,e,f, etc.
It would be much grateful if anyone can tell me.
Best regards,
mike
See Wolfram: Matrix Computations - specifically the section 'Generalized Eigenvalues'.
For n×n matrices A, B the generalized eigenvalues are the n
roots of its characteristic polynomial, p(𝛇) = det(A - 𝛇 B). For
each generalized eigenvalue, λ ∊ λ(A, B), the vectors, 𝛇, that
satisfy
A χ = λ B χ
are described as generalized eigenvectors.
Example using symbolic values:
matA = {{a11, a12}, {a21, a22}};
matB = {{b11, b12}, {b21, b22}};
Eigenvalues[{matA, matB}]
{(1/(2 (-b12 b21+b11 b22)))(a22 b11-a21 b12-a12 b21+a11 b22-Sqrt[(-a22 b11+a21 b12+a12 b21-a11 b22)^2-4 (-a12 a21+a11 a22) (-b12 b21+b11 b22)]),(1/(2 (-b12 b21+b11 b22)))(a22 b11-a21 b12-a12 b21+a11 b22+Sqrt[(-a22 b11+a21 b12+a12 b21-a11 b22)^2-4 (-a12 a21+a11 a22) (-b12 b21+b11 b22)])}
Eigenvectors[{matA, matB}]
...
I have a syntax problem solving a differential equation in Mathematica (10th version).
The input for the equation I need to solve is as follows:
solv = DSolve[{ a*u''[y] - b*u[y] == d, u'[0] == 0, u[1] == 0}, u, {y, -1, 1}]
Which after using ExpToTrig and FullSimplify I get the answer I am looking for:
(d (-1 + Cosh[(Sqrt[b] y)/Sqrt[a]] Sech[Sqrt[b]/Sqrt[a]]))/b
However, my problem comes when I want to place more coefficients in the equation. For example:
solv = DSolve[{ a* u''[y] - b* c* u[y] == d, u'[0] == 0, u[1] == 0}, u, {y, -1, 1}]
This time, I get for:
FullSimplify[ExpToTrig[Evaluate[u[y] /. solv]]]
The next answer:
(d (1 + E^((2 Sqrt[b] Sqrt[c])/Sqrt[a]) - E^(-((Sqrt[b] Sqrt[c] (-1 + y))/Sqrt[a])) - E^((Sqrt[b] Sqrt[c] (1 + y))/Sqrt[a])) (-1 + Tanh[(Sqrt[b] Sqrt[c])/Sqrt[a]]))/(2 b c)
Instead, when I merge b and c (substitute: bc=b*c):
solv = DSolve[{ a*u''[y] - bc*u[y] == d, u'[0] == 0, u[1] == 0}, u, {y, -1, 1}]
I get:
(d (-1 + Cosh[(Sqrt[bc] y)/Sqrt[a]] Sech[Sqrt[bc]/Sqrt[a]]))/bc
In my case I can't just substitute because there are too many equations and some of the parameters (coefficients) cancel.
Thanks!
Your issue is with FullSimplify. It deems the exp form more "simple" than the trig form so it is undoing what ExpToTrig is doing. Using just Simplify in its place will maintain the ExpToTrig conversion. My quick try below shows a comparison.
I need to use NDSolve which in turn uses the solution from another ODE as function in terms of output from another NDSolve.
If I use the exact solution from the first differential equation inside the NDSolve, it's OK. But when I use the same solution in the form of function (which uses InterpolatingFunction) it does not work.
I believe, it's got to do with the structure of NDSolve output. Could anyone please enlighten me on this. Will be of great help!
The code is:
feq = 2 V alpha fip F''[fi] - (V^2 - (V^2 + sigma - 2 fi) (F'[fi])^2 + (F'[fi])^4
Frange[lo_, hi_] :=
Module[{fii, sol},
sol = NDSolve[{(feq == 0 /.fi -> fii), F[0] == 0}, F, {fii, lo, hi}]]
eqpois = fi''[x] == ne[x] - F[fi[x]]/.sol
NDSolve[{eqpois, fi'[0] == 0, fi[0] == 0}, fi, {x,0,1}]
Here in order to find F[phi], I need to solve the 1st diff eq that is feq, which is solved by NDSolve inside the function Frange[lo,hi]. The solution is then used inside the second equation eqpois, which has to be solved using NDSolve again. The problem comes up in the second NDSolve, which does not produce the result. If I use the analytical solution of F[phi] in eqopis, then there is no problem.
Example Problem
I have done a little experiment with this. Let's take an example of coupled ODEs
1st eqn : dg/dx = 2f(g) with initial condition g(0) = 1
The function f(y) is a solution from another ODE, say,
2nd eqn : df/dy = 2y with IC f(0) = 0
The solution of the 2nd ODE is f(y) = y^2 which when put into the the 1st ODE becomes
dg/dx = 2 g^2 and the final solution is g(x) = 1/(1-2x)
The issue:
When I use DSolve, it finds the answer correctly
In[39]:= s = DSolve[{f'[y] == 2 y, f[0] == 0}, f, y]
Out[39]= {{f -> Function[{y}, y^2]}}
In[40]:= ss = DSolve[{g'[x] == 2 (f[g[x]]/.First#s), g[0] == 1}, g, x]
Out[40]= {{g -> Function[{y}, 1/(1 - 2 x)]}}
The problem comes when I use NDSolve
In[41]:= s = NDSolve[{f'[y] == 2 y, f[0] == 0}, f, {y, 1, 5}]
Out[41]= {{f -> InterpolatingFunction[{{1., 5.}}, <>]}}
In[42]:= ss1 = NDSolve[{g'[x] == 2 (Evaluate[f[g[x]]/.First#s1]), g[0] == 1}, g, {x, 1, 2}]
Out[42]= {}
The erros are:
During evaluation of In[41]:= InterpolatingFunction::dmval: Input value {2.01726} lies outside the range of data in the interpolating function. Extrapolation will be used. >>
During evaluation of In[41]:= InterpolatingFunction::dmval: Input value {2.01726} lies outside the range of data in the interpolating function. Extrapolation will be used. >>
During evaluation of In[41]:= InterpolatingFunction::dmval: Input value {2.04914} lies outside the range of data in the interpolating function. Extrapolation will be used. >>
During evaluation of In[41]:= General::stop: Further output of InterpolatingFunction::dmval will be suppressed during this calculation. >>
During evaluation of In[41]:= NDSolve::ndsz: At y == 0.16666654771477857, step size is effectively zero; singularity or stiff system suspected. >>
During evaluation of In[41]:= NDSolve::ndsz: At y == 0.16666654771477857, step size is effectively zero; singularity or stiff system suspected. >>
Any help in this regard will be highly appreciated!
--- Madhurjya
I got your simple example to work with a little mod ..
f0 = First#First#DSolve[{f'[y] == 2 y, f[0] == 0}, f, y]
g0 = g /.
First#First#DSolve[{g'[x] == 2 (f[g[x]] /. f0), g[0] == 1}, g, x]
fn = f /. First#First#NDSolve[{f'[y] == 2 y, f[0] == 0}, f, {y, 0, 10}]
gn = g /.
First#First#
NDSolve[{g'[x] == 2 (fn[g[x]]), g[0] == 1}, g, {x, 0, 9/20}]
GraphicsRow[{
Plot[{g0#x, gn#x}, {x, 0, 9/20},
PlotStyle -> {{Thick, Black}, {Thin, Red, Dashed}}],
Plot[{f#x /. f0, fn#x}, {x, 0, 2},
PlotStyle -> {{Thick, Black}, {Thin, Red, Dashed}}]}]
note we need to ensure the y range in the first NDSolve is sufficient to cover the expected range of g from the second. That is where all those interpolation range errors come from.
Hy everyones,
I've a little problem with a mathematica script which I need for fitting data points with a sum of 3 sine functions :
fit = NonlinearModelFit[Data,a1*Sin[b1*x + c1] + a2*Sin[b2*x + c2] + a3*Sin[b3*x + c3], {a1, b1,c1, a2, b2, c2, a3, b3, c3}, x]
I get this error :
NonlinearModelFit::cvmit: Failed to converge to the requested accuracy or precision within 100 iterations
I've tried with different starting values and with MaxIteration set to 10.000...
Maybe it's not the right way to do this kind of fitting. Does anyone have an idea about this?
Thanks!
Perhaps your data is too bad, but it works nicely with a good sample:
data = Table[{x, Sin[ x + .3] + 2 Sin[1.2 x] + 3 Sin[1.5 x + .5]},
{x, .01, 8 Pi, .001}];
fit = NonlinearModelFit[data,
a1*Sin[b1*x + c1] + a2*Sin[b2*x + c2] + a3*Sin[b3*x + c3],
{a1, b1, c1, a2, b2, c2, a3, b3, c3}, x]
Show[ListPlot[data], Plot[fit[x], {x, 0, 8 Pi}, PlotStyle -> Red], Frame -> True]