Symbolic Algebraic Simplifier - matlab

I'm trying to solve this equation for x (or y). Is there some way to do it in Matlab? The "simplify" function (even with "steps",100,"All", true) doesn't do it.
-k+Sqrt[x^2+y^2]+Sqrt[(x-ax)^2+y^2]+Sqrt[(x-bx)^2+(y-by)^2]

A symbolic solution does not exist in the general case, because the problem amounts to solving an 8th degree algebraic equation.
Defining the points M(x,y), O(0,0), A(ax,0) and B(bx,by) in the plane, the equation can be written as MO + MA + MB = k. The solution set M is the locus of points with constant sum of distances to 3 fixed points. This is called a 3-ellipse which is a curve of algebraic degree 2^3 = 8 in the general case.
If F is the Fermat point of triangle OAB and f = FO + FA + FB, then no solutions exist for k < f. More material and links related to 3-ellipses can be found on this multiellipse page.

Related

Polyfit with negative exponent

I want to fit a curve to my data points (x;y) that will have a formula as such:
1/y = (x^-1)*a + b
At first I wanna do this using Octave but later I have to code this into microcontroller using c.
A quick search on google and matlab documentation don't give an anwesr I can't find a function that do polyfit with elements with negative order.
Is there a special set of function for such operation or do I have to somehow transfer my formula to fit into standard math problem ?
Your unknowns are aand b which are both linear in your problem. So you can use the 1st order polynomial fitting. It is already in the form of a standard math problem. To see just rename
Y = a*X + b
with the known data vectors (or points)
Y = 1/y
X = 1/x
Thats all.

Fit a quadratic function of two variables (Practitioner Black Scholes Deterministic Volatility Functions)

I am attempting to fit the parameters of a deterministic volatility function for use in the practitioner Black Scholes model.
The formula for which I want to estimate the "a" parameters is:
sig = a0 + a1*K + a2*K^2 + a3*T + a4*T^2 + a5*KT
Where sig, K and T are known; I have multiple observations of K, T and sig combinations but only want a single set of "a" parameters.
How might I go about this? My google searches and own attempts all failed, unfortunately.
Thank you!
The function lsqcurvefit allows you to define the function that you want to fit. It should be straight forward from there on.
http://se.mathworks.com/help/optim/ug/lsqcurvefit.html
Some Mathematics
Notation stuff: index your observations by i and add an error term.
sig_i = a0 + a1*K_i + a2*K_i^2 + a3*T_i + a4*T_i^2 + a5*KT_i + e_i
Something probably not insane to do would be to minimize the square of the error term:
minimize (over a) \sum_i e_i^2
The solution to least squares is a simple linear algebra problem. (See https://stats.stackexchange.com/questions/186196/understanding-linear-algebra-in-ordinary-least-squares-derivation/186289#186289 for a solution if you really care.) (Further note: e_i is a linear function of a. I'm not sure why you would need lsqcurvefit as another answer suggested?)
Matlab Code for OLS (Ordinary Least Squares)
Assuming sig, K, T, and KT are n by 1 vectors
y = sig;
X = [ones(length(sig),1), K, K.^2, T, T.^2, KT];
a = X \ y; %basically computes a = inv(X'*X)*(X'*y) but in a better way
This an ordinary least squares regression of y on X.
Further Ideas
Depending on the distribution of your error terms, correlated error etc... regular OLS may be inefficient or possibly even inappropriate... I'm not familiar with the details of this problem to know. You may want to check what people do.
Eg. a technique that's less sensitive to big outliers is to minimize the absolute value of the error.
minimize (over a) \sum_i |a_i|
If you have a good, statistical model of how the data is generated you could do maximum likelihood estimation. Anyway... this rapidly devolve into a multi-quarter, statistics class.

How can I make all-in-one polynomial from multi-polynomial?

I'm not familiar with expert math. so I don't know where to start from.
I have get a some article like this. I am just following this article description. But this is not easy to me.
But I'm not sure how to make just one polynomial equation(or something like that) from above 4 polynomial equations. Is this can be possible way?
If yes, Would you please help me how to get a polynomial(or something like equation)? If not, would you let me know the reason of why?
UPDATE
I'd like to try as following
clear all ;
clc
ab = (H' * H)\H' * y;
y2 = H*ab;
Finally I can get some numbers like this.
So, is this meaning?
As you can see the red curve line, something wrong.
What did I miss anythings?
All the article says is "you can combine multiple data sets into one to get a single polynomial".
You can also go in the other direction: subdivide your data set into pieces and get as many separate ones as you wish. (This is called n-fold validation.)
You start with a collection of n points (x, y). (Keep it simple by having only one independent variable x and one dependent variable y.)
Your first step should be to plot the data, look at it, and think about what kind of relationship between the two would explain it well.
Your next step is to assume some form for the relationship between the two. People like polynomials because they're easy to understand and work with, but other, more complex relationships are possible.
One polynomial might be:
y = c0 + c1*x + c2*x^2 + c3*x^3
This is your general relationship between the dependent variable y and the independent variable x.
You have n points (x, y). Your function can't go through every point. In the example I gave there are only four coefficients. How do you calculate the coefficients for n >> 4?
That's where the matricies come in. You have n equations:
y(1) = c0 + c1*x(1) + c2*x(1)^2 + c3*x(1)^3
....
y(n) = c0 + c1*x(n) + c2*x(n)^2 + c3*x(n)^3
You can write these as a matrix:
y = H * c
where the prime denotes "transpose".
Premultiply both sides by transpose(X):
transpose(X)* y = transpose(H)* H * c
Do a standard matrix inversion or LU decomposition to solve for the unknown vector of coefficients c. These particular coefficients minimize the sum of squares of differences between the function evaluated at each point x and your actual value y.
Update:
I don't know where this fixation with those polynomials comes from.
Your y vector? Wrong. Your H matrix? Wrong again.
If you must insist on using those polynomials, here's what I'd recommend: You have a range of x values in your plot. Let's say you have 100 x values, equally spaced between 0 and your max value. Those are the values to plug into your H matrix.
Use the polynomials to synthesize sets of y values, one for each polynomial.
Combine all of them into a single large problem and solve for a new set of coefficients. If you want a 3rd order polynomial, you'll only have four coefficients and one equation. It'll represent the least squares best approximation of all the synthesized data you created with your four polynomials.

finding location of a point along the arc distance in matlab

I have a parabola y=a*(x-alpha)*(x-beta) where a, alpha, beta are known
let x1,y1 be initial points on the above parabola. I now have to cover a distance D along the arc from the initial point. The aim is to get the final position on the parabola after covering the required Arc distance.
One method is to keep checking from initial position to end point of parabola and check whether the integral is equal to the required distance. But this algorithm takes ages to complete as I need to do this many times.
Is there a faster way to do this ?
OK, a line distance on a parabola is not obtained by integration per se. I replaced your a with \gamma for convenience.
y = gamma(x-alpha)(x-beta) -> gamma*x^2 + (-gamma*alpha - gamma*beta)*x + alpha*beta*gamma
Substitute:
a = gamma
b = -gamma*alpha - gamma*beta
c = alpha*beta*gamma
So one can write:
y = a*x^2 + b*x + c
From this formula (parabola) the focal point f is determined by:
f = (1-D)/(4*a) - (-D)/(4*a)
In which
D = b^2 - 4*a*c
Now first define p as the perpendicular distance from a location on the curve to the vertical axis of symmetry x_p:
p = -b / (2*a) - x_p;
From this the arc length is calculated by:
h = p/2
q = sqrt(f^2+h^2)
s = h*q/f + f* ln (h*q/f)
In which s is the paramatric representations of your curve. The length of a curve is found by using two points s and then the distance between those points, so:
Distance = s_1 - s_2 = (h_1*q_1/f + f * ln (h_1*q_1/f)) - (h_2*q_2/f + f * ln (h_2*q_2/f))
With some simplifications:
Distance = (h_1*q_1 - h_2*q_2)/f + f* ln (( h_1 + q_1) / (h_2 + q_2))
To implement it fully in MatLab is up to you for now. Let me know if you run into any problems.
Good luck and have fun!
This is a nonlinear equation: you are given x1,y1 and seek x2, y2. x2 and y2 must satisfy the parabola equation and they must satisfy the arclength equation along a curve. http://en.wikibooks.org/wiki/Calculus/Arc_length
So that integral gives you the second equation. Now you have two equations and two unknowns - look up matlab fsolve http://www.mathworks.se/help/optim/ug/fsolve.html
assume the integral can't solve analytically (Can it?) then just solve it numerically using integrate - should still be much faster than just brute force search...
If you need to do this many times, make sure that the previous solutions are given as initial guesses for the next fsolve / integrate calls
I have no idea what are you using this for. But let me try to help you anyway
Well, this problem is not so hard to solve anallitically. I mean, it's just a simple line integral of 1 over a parabole. And good for you, it's been done before. http://en.wikipedia.org/wiki/Arc_length#Length_of_an_arc_of_a_parabola
All you need to do is to find the symmetry axis, not hard, X = (alpha + beta)/2, and the focus length (a little bit trickier, but if you google that I'm sure you'll find it). And I found it for you. https://math.stackexchange.com/questions/574688/what-is-the-focal-width-of-a-parabola shows the canonical form of the parabole, so all you need to do is to factor your equation (http://www.math-prof.com/Alg2/Alg2_Ch_40.asp)
Now the equation you need to solve is not pretty. Put everything in terms of p and let MatLab solve it for you (it shouldn't take forever).

Minimize quadratic form energy using matlab. Which function should I use?

I'm new to matlab and try to do some energy minimization work with it. The energy function takes a 3-channel image as input. For every channel, there's a energy term looks like this:
E = x'Ax + ||Bx||^2 + w*||x-c||^2,
where x,c are vectors of length N, A is a matrix of size N*N. A is sparse and positive semi-definite and has 25 non-zero elements per row, giving constraints to all elements of x. B is of size M*N. B is sparse too and has 2 non-zero elements per row. N is about 850,000. M is about 1,000,000. Although B gives more than N constraints, some elements of x have nothing to do with ||Bx||^2 term. The weight w of term ||x-c||^ is quite small, say 1e-3.
I've searched matlab documentation. It looks like I should use lsqnonlin for this problem. Is there a special designed function or option for quadratic form minimization in matlab?
For those who are familiar with computer vision literature, I'm actually trying to implement the algorithm in "Coherent Intrinsic Images from Photo Collections". The authors said they use matlab backslash operator to minimize the energy, but I can't see how a backslash operator can be used in quadratic form problem.
Yes, there is a function specifically for optimizing quadratic cost functions: quadprog. However, if you don't have any linear constraints, then you should be able to write your cost function as
E = x'Mx/2 + vx + k
Finding the point of zero gradient (hopefully a minimum) can then be achieved by taking first derivatives:
dE/dx = Mx + v
setting them to zero giving the solution:
x = -M\v