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}]
...
Related
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}
I am very new to Mathematica, and I am trying to solve the following problem.
I have a cubic equation of the form Z = aZ^3 + bZ^2 + a + b. The first thing I want to do is to get a function that solves this analytically for Z and chooses the minimal positive root for that, as a function of a and b.
I thought that in order to get the root I could use:
Z = Solve[z == az^3 + bz^2 + a + b, z];
It seems like I am not quite getting the roots, as I would expect using the general cubic equation solution formula.
I want to integrate the minimal positive root of Z over a and b (again, preferably analytically) from 0 to 1 for a and for a to 1 for b.
I tried
Y = Integrate[Z, {a, 0, 1}, {b, a, 1}];
and that does not seem to give any formula or numerical value, but just returns an integral. (Notice I am not even sure how to pick the minimal positive root, but I am playing around with Mathematica to try to figure it out.)
Any ideas on how to do this?
Spaces between a or b and z are important. You can get the roots by:
sol = z /. Solve[z == a z^3 + b z^2 + a + b, z]
However, are you sure this expression has a solution as you expect? For a=0.5 and b=0.5, the only real root is negative.
sol /. {a->0.5, b->0.5}
{-2.26953,0.634765-0.691601 I,0.634765+0.691601 I}
sol = z /. Solve[z == a z^3 + b z^2 + a + b, z];
zz[a0_ /; NumericQ[a0], b0_ /; NumericQ[b0]] :=
Min[Select[ sol /. {a -> a0, b -> b0} ,
Element[#, Reals] && # > 0 & ]]
This returns -infinty when there are no solutions. As sirintinga noted your example integration limits are not valid..
RegionPlot[NumericQ[zz[a, b] ] , {a, -1, .5}, {b, -.5, 1}]
but you can numerically integrate if you have a valid region..
NIntegrate[zz[a, b], {a, -.5, -.2}, {b, .8, .9}] ->> 0.0370076
Edit ---
there is a bug above Select in Reals is throwin away real solutions with an infinitesimal complex part.. fix as:..
zz[a0_ /; NumericQ[a0], b0_ /; NumericQ[b0]] :=
Min[Select[ Chop[ sol /. {a -> a0, b -> b0} ],
Element[#, Reals] && # > 0 & ]]
Edit2, a cleaner approach if you dont find Chop satisfyting..
zz[a0_ /; NumericQ[a0], b0_ /; NumericQ[b0]] :=
Module[{z, a, b},
Min[z /. Solve[
Reduce[(z > 0 && z == a z^3 + b z^2 + a + b /.
{ a -> a0, b -> b0}), {z}, Reals]]]]
RegionPlot[NumericQ[zz[a, b] ] , {a, -2, 2}, {b, -2, 2}]
NIntegrate[zz[a, b], {a, 0, .5}, {b, 0, .5 - a}] -> 0.0491321
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]
I have a differential system like
dx/dt = A x(t) + B y(t)
dy/dt = C x(t) + D y(t)
where A, B, C, and D are real constants. Now I need to explore the behavior of the system if A, instead of being a constant number, is a random number uniformly distributed between a given range. I just need to check qualitatively. I have no background on stochastic integrals, therefore I do not know if this is actually something related with the Ito integral (and this question https://mathematica.stackexchange.com/questions/3141/how-can-you-compute-it-integrals-with-mathematica) . In any case, I do not know how to solve this differential equation.
Any guidance is highly appreciated.
The standard way to solve your system is
FullSimplify[
DSolve[{y'[t] == a x[t] + b y[t], x'[t] == c x[t] + d y[t]}, {y, x}, t]]
Now, you should think WHAT do you want to explore when {a, b, c, d} are random parameters.
Edit
Perhaps you want something like this:
s = FullSimplify[
DSolve[{y'[t] == #[[1]] x[t] + #[[2]] y[t], x'[t] == #[[3]] x[t] + #[[4]] y[t],
x[0] == 1, y[0] == 1}, {y, x}, t]] & /# RandomReal[{-1, 1}, {30, 4}];
ParametricPlot[Evaluate[{x[t], y[t]} /. s[[All, 1]]], {t, 0, 1}]
I have, for example, the following polynomials to be equated, and I need to determine the unknowns c1, c2, c3, respectively. How can I do this automatically in mma, especially when there are many terms involved?
x+2*x^3+4*x^5==(c1+c2)*(x+2*c2*x^3)+(4-c1)*c3*x^5
Many thanks.
Edit: ideally, I want to equate the coefficients of left and right for the terms with equal exponents in x. Then solve this system of equations.
If this has to be true for all x, you could use SolveAlways (not tested)
SolveAlways[x+2*x^3+4*x^5==(c1+c2)*(x+2*c2*x^3)+(4-c1)*c3*x^5, x]
Try:
p1 = x + 2*x^3 + 4*x^5;
p2 = (c1 + c2)*(x + 2*c2*x^3) + (4 - c1)*c3*x^5;
Solve[CoefficientList[p2, x] == CoefficientList[p1, x], {c1, c2, c3}]
Out
{{c1 -> 0, c2 -> 1, c3 -> 1}}
This should do what you want even in more complicated situations.
eq = x + 2*x^3 + 4*x^5 == (c1 + c2)*(x + 2*c2*x^3) + (4 - c1)*c3*x^5;
list = CoefficientList[eq /. Equal[k__, l__] -> Plus[k, -l], x];
vars = Variables#list;
Solve[list == Table[0, {i, First#Dimensions#list}], vars]
Out[1] := {{c1 -> 0, c2 -> 1, c3 -> 1}}