MATLAB: Solve non linear equations system

can't reload (windows)equationnonlinearsolvesystem

Hi, I'm a newbie, I have never used Matlab but I have to use it to solve a complex problem as a part of a modelisation project. I need to solve 4 non linear equation systems, each one is a 2 equations system with two variables (x and y) and t is a constant. I would like to get the results for x and y depending on t. I have some boundaries conditions, 6.3*10^10>x>0, 6.3*10^10>y>0 and 300>t>0. One of my 4 system for example:
0=(10^(-41)*(10^9)*(e^((1-2*0.2)*160)-1))/(1-2*0.2)-((e^(-160)-1)/(0.2*(1-0.2)))*(0.91-0.35*(((12.6*10^(11)-t*y)^2-(12.6*10^11-t*x-t*y)^2)/(12.6*10^11-t*x-t*y)^2)-25/(12.6*10^11-t*y)-(x+y)*2*t*0.35*(((12.6*10^11-t*y)^2)/(12.6*10^11-t*x-t*y)^3))+(e^(-0.2*160)-1)/0.2*(-0.91*t+0.35*(2*(t^2)*x*(12.6*10^11-t*x-t*y)+(t^3)*(x^2))/((12.6*10^11-t*x-t*y)^2)-(25*t)/(12.6*10^11-t*y))
0=(2.7*10^(-23)*(e^((1-2*0.2)*90)-1))/(1-2*0.2)-((e^(-90)-1)/(0.2*(1-0.2)))*(0.91-0.79*(((12.6*10^(11)-t*x)^2-(12.6*10^11-t*y-t*x)^2)/(12.6*10^11-t*y-t*x)^2)-42/(12.6*10^11-t*x)-(y+x)*2*t*0.79*(((12.6*10^11-t*x)^2)/(12.6*10^11-t*y-t*x)^3))+(e^(-0.2*90)-1)/0.2*(-0.91*t+0.79*(2*(t^2)*y*(12.6*10^11-t*y-t*x)+(t^3)*(y^2))/((12.6*10^11-t*y-t*x)^2)-(42*t)/(12.6*10^11-t*x))
Could you please help me to use Matlab in order to solve my problem? Thank you very much

Best Answer

You need to do a couple of steps. First, make a function which returns the equation you want optimized:
function [F] = fun_t(a,t)
x = a(1);
y = a(2);
e = exp(1);
F = zeros(2,1);
F(1) = (10^(-41)*(10^9)*(e^((1-2*0.2)*160)-1))/(1-2*0.2)-((e^(-160)-1)/(0.2*(1-0.2)))*(0.91-0.35*(((12.6*10^(11)-t*y)^2-(12.6*10^11-t*x-t*y)^2)/(12.6*10^11-t*x-t*y)^2)-25/(12.6*10^11-t*y)-(x+y)*2*t*0.35*(((12.6*10^11-t*y)^2)/(12.6*10^11-t*x-t*y)^3))+(e^(-0.2*160)-1)/0.2*(-0.91*t+0.35*(2*(t^2)*x*(12.6*10^11-t*x-t*y)+(t^3)*(x^2))/((12.6*10^11-t*x-t*y)^2)-(25*t)/(12.6*10^11-t*y));
F(2) = (2.7*10^(-23)*(e^((1-2*0.2)*90)-1))/(1-2*0.2)-((e^(-90)-1)/(0.2*(1-0.2)))*(0.91-0.79*(((12.6*10^(11)-t*x)^2-(12.6*10^11-t*y-t*x)^2)/(12.6*10^11-t*y-t*x)^2)-42/(12.6*10^11-t*x)-(y+x)*2*t*0.79*(((12.6*10^11-t*x)^2)/(12.6*10^11-t*y-t*x)^3))+(e^(-0.2*90)-1)/0.2*(-0.91*t+0.79*(2*(t^2)*y*(12.6*10^11-t*y-t*x)+(t^3)*(y^2))/((12.6*10^11-t*y-t*x)^2)-(42*t)/(12.6*10^11-t*x));
end
Save this in your working directory. This is for your example system, and I'm assuming you've written it down properly and everything, since I just copied it from your post. You'll want to check this is correct.
I would first do the simplest thing, which is to just try and solve this directly without worrying about the constraints, then checking afterwards if they are met. You can do this using fsolve:
t = 5; %some value you want
func = @(a)fun_t(a,t)
x0 = [10,10]; % a guess for the solution
x = fsolve(func,x0);
I think you might have a mistake in your system, since when I run this it evaluates to be perfectly flat. You'd better check that it's correct, but this just means changing F(1) and F(2) in the above function.
If you need the constraints, you can do the following instead of fsolve.
lb = [0,0];
ub = [6.3*10^10,6.3*10^10];
rng default
x0 = [10,10];
[x res] = lsqnonlin(func,x0,lb,ub)
See also here for other techniques you can try. Some are easier than others.