Solving Trigonometric Equations in wxMaxima - maxima

I am new in wxmaxima and i try to learn how can i solve trigonometric equations.
Can you help me with the sample program ? for example
Sin(X)+Cos(Y) = sqrt(3)
Sin(X)*Cos(Y) = 3/4
How can i get X,Y [0,2*pi] ?

Related

regression with stochastic gradient descent algorithm

I am studying regression with Machine Learning in Action book and I saw a source like below :
def stocGradAscent0(dataMatrix, classLabels):
m, n = np.shape(dataMatrix)
alpha = 0.01
weights = np.ones(n) #initialize to all ones
for i in range(m):
h = sigmoid(sum(dataMatrix[i]*weights))
error = classLabels[i] - h
weights = weights + alpha * error * dataMatrix[i]
return weights
You may guess what the code means. But I didn't understand it. I read the book several times and searched related stuff like wiki or google, where exponential function is from to get weights for minimum differences. And why do we get proper weight using the exponential function with sum of X*weights? It would be kind of OLS. Anyway then we get the result like below:
Thanks!
It just the basics in linear regression. In the for loop it tries to calculate the error function
Z = β₀ + β₁X ; where β₁ AND X are matrices
hΘ(x) = sigmoid(Z)
i.e. hΘ(x) = 1/(1 + e^-(β₀ + β₁X)
then update the weights. normally it's better to give it a high number for iterations in the for loop like 1000, m it would be small i guess.
i want to explain more but i can't explain better than this dude here
Happy learning!!

Analytic solution to an equation including the error function in 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!"

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);

Minimize a equation using opencv

I need to solve the following equation:
I Know the matrix G, how can I find the the matrix p subject to ||p|| = 1.
Currently I am solving in opencv as follows:
Mat w, u, EigenVectors;
SVD::compute(A, w, u, EigenVectors);
Mat p = EigenVectors.row(EigenVectors.rows-1);
I want to know how can I ensure the condition ||p|| = 1.
Also I want to know the significance and meaning of other rows/cols of the EigenVectors(transposed) ?
I believe you can use cv::SVD::solveZ(). It finds a unit-length solution x of a singular linear system A * x = 0
Looks like you need to use Lagrange multipliers method.
As I know, OpenCV have no ready to use tools for that.
Good example for MATLAB: Lagrange Multipliers

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