Analytic solution to an equation including the error function in Maxima - maxima

Maxima does not seem to come up with an analytic solution to this equation which includes the error function. The independent variable here is "p" and the dependent variable to be solved for is "x".
see an illustration of equation follow link
(%i3) solveexplicit:true$ ratprint:false$ fpprintprec:6$
(%i4) eqn: (sqrt(%pi)*(25*2^(3/2)*p-25*sqrt(2))*erf(1/(25*2^(3/2)*x))*x+1)/(25*p) = 0.04;
(%i5) solve (eqn, x);
(%o5) []
(%i6) eqn, [p=2,x=0.00532014],numer;
(%o6) 0.04=0.04
Any help or pointing in the right direction is appreciated.

As far as I know, Maxima can't solve equations containing erf. You can get a numerical result via find_root:
(%i5) find_root (eqn, x, 0.001, 0.999), p=2;
(%o5) 0.005320136894034347
As for symbolic solutions, I worked with the equation a little bit. One can get it into the form erf(something/x)*x = otherstuff, or equivalently erf(y) = somethingelse*y where y = something/x and somethingelse = otherstuff/something if I'm not mistaken. I don't know anything in particular about equations of that form, but perhaps you can find something.

Yes, solve can only do polynominals. I used the series expansion for small values of x and the accuracy is good enough.
(%i11) seriesE: 1$
termE: erf(x)$
for p: 1 unless p > 3 do
(termE: diff (termE, x)/p,
seriesE: seriesE + subst (x=0, termE)*x^p)$
seriesE;
(%o11) -(2*x^3)/(3*sqrt(%pi))+(2*x)/sqrt(%pi)+1
However, the "Expression longer than allowed by the configuration setting!"

Related

Maxima numerical integration syntax

I'm trying to obtain a numerical solution to the following integral:
1
The correct answer is -0.324 + 0.382i but as seen below I am not getting a numerical answer and would appreciate help with the Maxima syntax.
2
Perhaps related to why I am not getting a numerical output are two specific questions:
I read that e and i in Maxima need to be preceded by % in input but should these also appear as %e and %i as seen in the Maxima output?
Why is dy missing at the end of the integral in the Maxima output?
Thank you!
Looks to me like your input is okay, however, the function to compute approximations to integrals is named quad_qags. (There are actually several related functions. See ?? quad_ for more info.) Also, a wrinkle here is that the integrand is a complex-valued function (of a real variable), and quad_qags can only work on real-valued integrands, so we'll have to work around it. Here's how I would arrange it.
myintegrand: exp(%i*(1 + %i*y))/(1 + %i*y + 1/(1 + %i*y));
result_realpart: quad_qags (realpart (myintegrand), y, 0, 6);
result_imagpart: quad_qags (imagpart (myintegrand), y, 0, 6);
result: result_realpart[1] + %i*result_imagpart[1];
I get 0.3243496676292901*%i + 0.3820529930785175 as the final result. That's a little different from what you said; maybe a minus sign went missing? or there's a missing or extra factor of %i?
A quick approximation
0.1 * lsum (x, x, float (rectform (makelist (ev (myintegrand, y = k/10), k, 0, 60))));
seems to show the result from quad_qags is reasonable.

Cannot solve this algebraic equation in Maxima?

Hello i am trying to solve a algebric equation in maxima, the equation has alpha, delta and psi as variable. I want the alpha in equation to be solved in terms of psi and delta. I tried using the solve command but i am getting alpha in terms of alpha.
Here is the equation to solve Equation to solve
And this is the output from maxima
.
This is the code i am trying -->
solve([(sqrt(-4*alpha*delta*psi-4*delta*psi+alpha^2*delta^2)/(delta^2+delta)-(alpha*delta/(delta^2+delta)))/2-sqrt(4*alpha^2*delta^2+6*alpha*delta^2+3*delta^2+2*alpha^2*delta+4*alpha*delta+2*delta)/(3*delta^2+2*delta)+alpha*delta/(3*delta^2+2*delta)=0],alpha);
Thank you
The problem with that algebraic equation is that involves square roots,or radicals and normal polynomial, and that that type of equation is not easy to solve, take a look at this equation:
(%i30) solve(x=sqrt(x+6),x);
(%o30) x = sqrt{x+6}
So Maxima doesn't return any value, but for example other software Mathematica does.
Let's square both sides of equation and try to solve it
(%i31) solve(x^2=x+6,x);
(%o31) x=3 , x=-2
we get two solutions, let's try with first equation:
3 = sqrt(3+6) => 3 = sqrt(9) => 3 = 3
-2 = sqrt(-2+6) => -2 = sqrt(4) => -2 = 2 ??????
So the second solution is not valid,
maxima solve program in Macsyma/Maxima generally avoids methods that
produce false solutions, like "square both sides". It may still
make errors based on dividing by expressions that appear to be
non-zero, but actually ARE zero, and maybe some other similar
situations.
from this mailing list
In your case I will factor the equation to get a simplified version but with those free variable this will be difficult so, try to assume some values for psi and delta:
(%i26) solve(factor((sqrt(-4*alpha*delta*psi-4*delta*psi+alpha^2*delta^2)/(delta^2+delta)-(alpha*delta/(delta^2+delta)))/2-sqrt(4*alpha^2*delta^2+6*alpha*delta^2+3*delta^2+2*alpha^2*delta+4*alpha*delta+2*delta)/(3*delta^2+2*delta)+alpha*delta/(3*delta^2+2*delta))=0,alpha);
(\%o26) \left[ \alpha=\ifrac{\left(3\,\delta+2\right)\,\isqrt{\left(-4\,\alpha-4\right)\,\delta\,\psi+\alpha^2\,\delta^2}+\left(-2\,\delta-2\right)\,\isqrt{\left(4\,\alpha^2+6\,\alpha+3\right)\,\delta^2+\left(2\,\alpha^2+4\,\alpha+2\right)\,\delta}}{\delta^2} \right]
Expand your Equation and try to remove square roots or some assumptions:
Equation : (sqrt(-4*alpha*delta*psi-4*delta*psi+alpha^2*delta^2)/(delta^2+delta)-(alpha*delta/(delta^2+delta)))/2-sqrt(4*alpha^2*delta^2+6*alpha*delta^2+3*delta^2+2*alpha^2*delta+4*alpha*delta+2*delta)/(3*delta^2+2*delta)+alpha*delta/(3*delta^2+2*delta);

what does this notation mean <x1,x2>?

I was reading about k-strong convexity and came a across an equation like this
f(x_1) >= f(x_2) + <\Delta f(x_2), x_1-x_2> + (k/2)*(||x_1-x_2||^2)
Could some one explain what the notation <> means?
Sorry for the errors with latex.
<x,y> is the dot (scalar) product of x and y
<x,y> = y'*x
as y' is the tronspose of y, for more you can cheek scalar product
I think that these part of quantum mechanics, especially matrix mechanics
< x1 is called bra vector and x2> is called as the ket vector. Please check with quantum mechanics book. Please check the book by Dirac on quantum mechanics.

Maxima plot not working

What am I doing wrong in this code?
atvalue(y(x),[x=0],1)$
desolve(diff(y(x),x)=y(x),y(x));
plot2d(y(x),[x,-6,6]);
Output:
plot2d: expression evaluates to non-numeric value everywhere in plotting range.
plot2d: nothing to plot
false
I want to plot y(x) which is obtained from a differential equation.
In Maxima y(x) = ... is an equation, and y(x) := ... is a function, and those two things are different. Try this:
atvalue (y(x), [x=0], 1)$
desolve (diff(y(x),x)=y(x), y(x));
define (y(x), rhs(%));
plot2d (y(x), [x, -6, 6]);
Here define(y(x), ...) is a different way to define a function. define evaluates the function body rhs(%) to yield exp(x) but := quotes it (not what you want).
The reason is that the result you see after the desolve does not mean y is defined as a function of x; in fact you obtain the same error if you change y(x) with f(x) (or any other unknown function) in plot2d. See the difference:
(%i9) atvalue(y(x),[x=0],1)$
(%i10) desolve(diff(y(x),x)=y(x),y(x));
x
(%o10) y(x) = %e
(%i11) y(x);
(%o11) y(x)
(%i12) y(x):=%e^x;
x
(%o12) y(x) := %e
(%i13) y(x);
x
(%o13) %e
I don't know if there's a way to “transform” the equation (the result) into a function definition automatically. If I find a way, I will complete the answer.

How does fitEllipse work in OpenCV?

I am working with opencv and I need to understand how does the function fitEllipse exactly works. I looked at the code at (https://github.com/Itseez/opencv/blob/master/modules/imgproc/src/shapedescr.cpp) and I know it uses least-squares to determine the likely ellipses. I also looked at the paper given in the documentation(Andrew W. Fitzgibbon, R.B.Fisher. A Buyer’s Guide to Conic Fitting. Proc.5th British Machine Vision Conference, Birmingham, pp. 513-522, 1995.)
But I cannot understand exactly the algorithm. For example, why does it need to solve 3 times the least square problem? why bd is initialized to 10000 before the first svd(I guess it is juste a random value for the initialization but why this value can be random?)? why does the values in Ad needs to be negative before the first svd?
Thank you!
Here is Matlab code.. it might help
function [Q,a]=fit_ellipse_fitzgibbon(data)
% function [Q,a]=fit_ellipse_fitzgibbon(data)
%
% Ellipse specific fit, according to:
%
% Direct Least Square Fitting of Ellipses,
% A. Fitzgibbon, M. Pilu and R. Fisher. PAMI 1996
%
%
% See Also:
% FIT_ELLIPSE_LS
% FIT_ELLIPSE_HALIR
[m,n] = size(data);
assert((m==2||m==3)&&n>5);
x = data(1,:)';
y = data(2,:)';
D = [x.^2 x.*y y.^2 x y ones(size(x))]; % design matrix
S = D'*D; % scatter matrix
C(6,6)=0; C(1,3)=-2; C(2,2)=1; C(3,1)=-2; % constraints matrix
% solve the generalized eigensystem
[V,D] = eig(S, C);
% find the only negative eigenvalue
[n_r, n_c] = find(D<0 & ~isinf(D));
if isempty(n_c),
warning('Error getting the ellipse parameters, will do LS');
[Q,a] = fit_ellipse_ls(data); %
return;
end
% the parameters
a = V(:, n_c);
[A B C D E F] = deal(a(1),a(2),a(3),a(4),a(5),a(6)); % deal is slow!
Q = [A B/2 D/2; B/2 C E/2; D/2 E/2 F];
end % fit_ellipse_fitzgibbon
Fitzibbon solution has some numerical stability though. See the work of Halir for a solution to this.
It is essentially least squares solution, but specifically designed so that it will produce a valid ellipse, not just any conic.

Resources