# How to simplify non-linear equations for lsqnonlin

1 view (last 30 days)
john zhang on 25 Sep 2020
Commented: john zhang on 7 Oct 2020
I am now trying to simplify the following non-linear quations for lsqnonlin. Could anyone give me some hint on how to do it?
the d is the unknow variable to be solved by lsqnonlin, but it is the upper limit of integral. I believe there should be much more elegant codes....
clc
clear
a=[0.0025
0.0715
2.4271
38.8184
-0.2403
828.9618];
x=-10:2:8;
N=length(x);
X=zeros(N);% xi-xj matrix
for i=1:N
for j=1:N
X(i,j)=x(i)-x(j);
end
end
d = @(d1,d2,d3,d4,d5,d6,d7,d8,d9,d10) [d1 d2 d3 d4 d5 d6 d7 d8 d9 d10]; % unknown variable vector
Fints1=@(d)integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(1,1).^2./(a(4)+a(5)*t).^2).^a(6),0,d(1))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(1,2).^2./(a(4)+a(5)*t).^2).^a(6),0,d(2))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(1,3).^2./(a(4)+a(5)*t).^2).^a(6),0,d(3))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(1,4).^2./(a(4)+a(5)*t).^2).^a(6),0,d(4))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(1,5).^2./(a(4)+a(5)*t).^2).^a(6),0,d(5))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(1,6).^2./(a(4)+a(5)*t).^2).^a(6),0,d(6))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(1,7).^2./(a(4)+a(5)*t).^2).^a(6),0,d(7))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(1,8).^2./(a(4)+a(5)*t).^2).^a(6),0,d(8))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(1,9).^2./(a(4)+a(5)*t).^2).^a(6),0,d(9))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(1,10).^2./(a(4)+a(5)*t).^2).^a(6),0,d(10));
Fints2=@(d)integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(2,1).^2./(a(4)+a(5)*t).^2).^a(6),0,d(1))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(2,2).^2./(a(4)+a(5)*t).^2).^a(6),0,d(2))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(2,3).^2./(a(4)+a(5)*t).^2).^a(6),0,d(3))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(2,4).^2./(a(4)+a(5)*t).^2).^a(6),0,d(4))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(2,5).^2./(a(4)+a(5)*t).^2).^a(6),0,d(5))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(2,6).^2./(a(4)+a(5)*t).^2).^a(6),0,d(6))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(2,7).^2./(a(4)+a(5)*t).^2).^a(6),0,d(7))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(2,8).^2./(a(4)+a(5)*t).^2).^a(6),0,d(8))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(2,9).^2./(a(4)+a(5)*t).^2).^a(6),0,d(9))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(2,10).^2./(a(4)+a(5)*t).^2).^a(6),0,d(10));
Fints3=@(d)integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(3,1).^2./(a(4)+a(5)*t).^2).^a(6),0,d(1))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(3,2).^2./(a(4)+a(5)*t).^2).^a(6),0,d(2))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(3,3).^2./(a(4)+a(5)*t).^2).^a(6),0,d(3))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(3,4).^2./(a(4)+a(5)*t).^2).^a(6),0,d(4))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(3,5).^2./(a(4)+a(5)*t).^2).^a(6),0,d(5))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(3,6).^2./(a(4)+a(5)*t).^2).^a(6),0,d(6))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(3,7).^2./(a(4)+a(5)*t).^2).^a(6),0,d(7))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(3,8).^2./(a(4)+a(5)*t).^2).^a(6),0,d(8))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(3,9).^2./(a(4)+a(5)*t).^2).^a(6),0,d(9))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(3,10).^2./(a(4)+a(5)*t).^2).^a(6),0,d(10));
Fints4=@(d)integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(4,1).^2./(a(4)+a(5)*t).^2).^a(6),0,d(1))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(4,2).^2./(a(4)+a(5)*t).^2).^a(6),0,d(2))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(4,3).^2./(a(4)+a(5)*t).^2).^a(6),0,d(3))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(4,4).^2./(a(4)+a(5)*t).^2).^a(6),0,d(4))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(4,5).^2./(a(4)+a(5)*t).^2).^a(6),0,d(5))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(4,6).^2./(a(4)+a(5)*t).^2).^a(6),0,d(6))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(4,7).^2./(a(4)+a(5)*t).^2).^a(6),0,d(7))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(4,8).^2./(a(4)+a(5)*t).^2).^a(6),0,d(8))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(4,9).^2./(a(4)+a(5)*t).^2).^a(6),0,d(9))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(4,10).^2./(a(4)+a(5)*t).^2).^a(6),0,d(10));
Fints5=@(d)integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(5,1).^2./(a(4)+a(5)*t).^2).^a(6),0,d(1))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(5,2).^2./(a(4)+a(5)*t).^2).^a(6),0,d(2))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(5,3).^2./(a(4)+a(5)*t).^2).^a(6),0,d(3))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(5,4).^2./(a(4)+a(5)*t).^2).^a(6),0,d(4))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(5,5).^2./(a(4)+a(5)*t).^2).^a(6),0,d(5))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(5,6).^2./(a(4)+a(5)*t).^2).^a(6),0,d(6))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(5,7).^2./(a(4)+a(5)*t).^2).^a(6),0,d(7))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(5,8).^2./(a(4)+a(5)*t).^2).^a(6),0,d(8))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(5,9).^2./(a(4)+a(5)*t).^2).^a(6),0,d(9))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(5,10).^2./(a(4)+a(5)*t).^2).^a(6),0,d(10));
Fints6=@(d)integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(6,1).^2./(a(4)+a(5)*t).^2).^a(6),0,d(1))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(6,2).^2./(a(4)+a(5)*t).^2).^a(6),0,d(2))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(6,3).^2./(a(4)+a(5)*t).^2).^a(6),0,d(3))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(6,4).^2./(a(4)+a(5)*t).^2).^a(6),0,d(4))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(6,5).^2./(a(4)+a(5)*t).^2).^a(6),0,d(5))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(6,6).^2./(a(4)+a(5)*t).^2).^a(6),0,d(6))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(6,7).^2./(a(4)+a(5)*t).^2).^a(6),0,d(7))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(6,8).^2./(a(4)+a(5)*t).^2).^a(6),0,d(8))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(6,9).^2./(a(4)+a(5)*t).^2).^a(6),0,d(9))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(6,10).^2./(a(4)+a(5)*t).^2).^a(6),0,d(10));
Fints7=@(d)integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(7,1).^2./(a(4)+a(5)*t).^2).^a(6),0,d(1))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(7,2).^2./(a(4)+a(5)*t).^2).^a(6),0,d(2))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(7,3).^2./(a(4)+a(5)*t).^2).^a(6),0,d(3))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(7,4).^2./(a(4)+a(5)*t).^2).^a(6),0,d(4))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(7,5).^2./(a(4)+a(5)*t).^2).^a(6),0,d(5))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(7,6).^2./(a(4)+a(5)*t).^2).^a(6),0,d(6))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(7,7).^2./(a(4)+a(5)*t).^2).^a(6),0,d(7))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(7,8).^2./(a(4)+a(5)*t).^2).^a(6),0,d(8))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(7,9).^2./(a(4)+a(5)*t).^2).^a(6),0,d(9))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(7,10).^2./(a(4)+a(5)*t).^2).^a(6),0,d(10));
Fints8=@(d)integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(8,1).^2./(a(4)+a(5)*t).^2).^a(6),0,d(1))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(8,2).^2./(a(4)+a(5)*t).^2).^a(6),0,d(2))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(8,3).^2./(a(4)+a(5)*t).^2).^a(6),0,d(3))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(8,4).^2./(a(4)+a(5)*t).^2).^a(6),0,d(4))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(8,5).^2./(a(4)+a(5)*t).^2).^a(6),0,d(5))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(8,6).^2./(a(4)+a(5)*t).^2).^a(6),0,d(6))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(8,7).^2./(a(4)+a(5)*t).^2).^a(6),0,d(7))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(8,8).^2./(a(4)+a(5)*t).^2).^a(6),0,d(8))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(8,9).^2./(a(4)+a(5)*t).^2).^a(6),0,d(9))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(8,10).^2./(a(4)+a(5)*t).^2).^a(6),0,d(10));
Fints9=@(d)integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(9,1).^2./(a(4)+a(5)*t).^2).^a(6),0,d(1))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(9,2).^2./(a(4)+a(5)*t).^2).^a(6),0,d(2))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(9,3).^2./(a(4)+a(5)*t).^2).^a(6),0,d(3))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(9,4).^2./(a(4)+a(5)*t).^2).^a(6),0,d(4))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(9,5).^2./(a(4)+a(5)*t).^2).^a(6),0,d(5))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(9,6).^2./(a(4)+a(5)*t).^2).^a(6),0,d(6))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(9,7).^2./(a(4)+a(5)*t).^2).^a(6),0,d(7))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(9,8).^2./(a(4)+a(5)*t).^2).^a(6),0,d(8))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(9,9).^2./(a(4)+a(5)*t).^2).^a(6),0,d(9))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(9,10).^2./(a(4)+a(5)*t).^2).^a(6),0,d(10));
Fints10=@(d)integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(10,1).^2./(a(4)+a(5)*t).^2).^a(6),0,d(1))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(10,2).^2./(a(4)+a(5)*t).^2).^a(6),0,d(2))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(10,3).^2./(a(4)+a(5)*t).^2).^a(6),0,d(3))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(10,4).^2./(a(4)+a(5)*t).^2).^a(6),0,d(4))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(10,5).^2./(a(4)+a(5)*t).^2).^a(6),0,d(5))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(10,6).^2./(a(4)+a(5)*t).^2).^a(6),0,d(6))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(10,7).^2./(a(4)+a(5)*t).^2).^a(6),0,d(7))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(10,8).^2./(a(4)+a(5)*t).^2).^a(6),0,d(8))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(10,9).^2./(a(4)+a(5)*t).^2).^a(6),0,d(9))...
+integral(@(t)-(a(1)+a(2).*exp(-t./a(3))).*(1-X(10,10).^2./(a(4)+a(5)*t).^2).^a(6),0,d(10));
d_0=ones(N,1)'; % initial guess
lb=zeros(N,1)'; % lower bounds
dx=lsqnonlin(@CalcTemps,d_0,lb)';
function fun = CalcTemps(d)
fun(1) = Fints1(d);
fun(2) = Fints2(d);
fun(3) = Fints3(d);
fun(4) = Fints4(d);
fun(5) = Fints5(d);
fun(6) = Fints6(d);
fun(7) = Fints7(d);
fun(8) = Fints8(d);
fun(9) = Fints9(d);
fun(10) = Fints10(d);
end

Ayush Gupta on 7 Oct 2020
To simplify equations in MATLAB, simplify function can be used for it. To read about it and have some examples to check how it works, read here.
john zhang on 7 Oct 2020
What I mean "simplify" is how to write "Fints" functions to a simple form. Now I have to write the Fints functions one by one and they are too long. Are there any method to write them in a shorter/simpler form? Currently, I have to rewrite all Fints functions if I change the number of variables in d.
Thank you.

### Categories

Find more on Newton-Raphson Method in Help Center and File Exchange

R2019b

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!