Search code examples
matlabequationnumerical-methodsexponential

Matlab: Solve Exponential Equation with two unknown parameters


I have a Matrix called A. For example the following:

A = [1 2 3; 3 4 1; 2 4 4]

Now I have the following equation: A(x,y) = (j^x)*(i^y)

j and i are normal values (dimension 1x1), not indices of a matrix. ^

Lets make an example:

A(1,1) = 1 (First value of the Matrix)
1 = (j^1)*(i^1)

And a second one:

A(1,2) = 3
3 = (j^1)*(i^2)

Is there a possibility to receive one solution for the two parameters using Matlab?


Solution

  • Here is some code that can find the best solution to your problem, if there is one. In this case, there is no reasonable solution, but defining A by M([4 2]) (for example) does work reasonably well.

    A = [1 2 3; 3 4 1; 2 4 4] %// the A matrix
    [C,R]=meshgrid(1:3) %// create matrices of row/column indices
    M=@(xy) xy(2).^C.*xy(1).^R %// calculates matrix of elements j^x*i^y
    d=@(xy) A-M(xy) %// calculates difference between A and the calculated i^x*y^j matrix
    
    r=fsolve(@(xy) norm(d(xy)),[1 1]) %// use fsolve to attempt to find a solution
    d(r) %// show resulting difference between target matrix and solution matrix
    norm(d(r)) %// norm of that matrix
    M(r) %// show the solution matrix