Hello,
I am trying to write a function that solves a non linear system of equations. In my exercise I have 2,3 and 4 dimensional equation system. I am not allowed to use fsolve function. I also have a function called "Score4" which is suppose to calculate the score of my function ( should be around 1 if the code that I wrote is correct).
Below you will find the score and the code that I wrote.
Thank you in advance for your time.
function [score,error,details] = Score4()
A{1} = @(x)[4*cos(x(1)),2*cos(x(1)+x(2));
5*sin(x(1)),1*sin(x(1)+x(2))];
A{2} = @(x)[1,0,0;0,cos(x(1)),-sin(x(2));0,sin(x(2))^2,cos(x(1))];
A{3} = @(x)[cos(x(1)),sin(x(1)),0,-x(3);
-sin(x(1))*cos(x(4)),cos(x(1))*cos(x(4)),sin(x(4))*sin(x(5)),-x(2)*sin(x(4))*cos(x(5));
sin(x(4))*sin(x(1)),-cos(x(1))*sin(x(4)),cos(x(4))*sin(x(5)),-x(2)*cos(x(4))*cos(x(5));
RootProblem = @(z) A{i}(z)*y0{i}-y{i};
x = nlinSolve(RootProblem,x0{i});
output = A{i}(x)*y0{i}-y{i};
details.(['time',num2str(i)]) = T;
details.(['error',num2str(i)]) = Err;
To solve this problem I was thinking to use Newton method but I am having a lot of problems. Can someone give me some suggestions how to improve my code and what am I doing wrong. My code is as follows:
function x = nlinSolve (g,x0)
select = @(g,r,c) g(r,c);
G1 = @(x)select(g(x), 1, 1);
G2 = @(x)select(g(x), 2, 1);
G3 = @(x)select(g(x), 3, 1);
G4 = @(x)select(g(x), 4, 1);
G5 = @(x)select(g(x), 5, 1);
Jakobian(k,n)= Derivative(eval(['G',num2str(k)]),x,x(n),n);
x = x-inv(Jakobian)*g(x);
function J = Derivative(G,x,xm,m)
Now this code is clearly not working, I am messing up something. Also the score should be around 1 at the end.
If anyone can help me that would be more than appritiated.