Solve non linear equations system
1 view (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
jgg
on 21 Jan 2016
Edited: jgg
on 22 Jan 2016
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)
7 Comments
jgg
on 22 Jan 2016
This is a math problem you're going to have to solve; does this even have a solution? Your Matlab code is fine, you're just going to have to work on it for a while.
You should accept this answer so other people can see what you did to try and solve this problem.
More Answers (1)
Krisda
on 16 Feb 2023
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
t = 5; %some value you want
func = @(a)fun_t(a,t)
x0 = [10,10]; % a guess for the solution
x = fsolve(func,x0);
lb = [0,0];
ub = [6.3*10^10,6.3*10^10];
rng default
x0 = [10,10];
[x res] = lsqnonlin(func,x0,lb,ub)
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!