problem with VPASOLVE and FSOLVE
7 views (last 30 days)
Show older comments
Deepti Ranjan Majhi
on 3 Jun 2021
Commented: Deepti Ranjan Majhi
on 3 Jun 2021
Hi all, I want to estimate four unknowns from four nonlinear equations. The problem with FSOLVE is that while changing the initial conditions, its corresponding values are also changing. I want a solution that shouldn't depend on the initial conditions. If I run the same equations using VPASOLVE without the initial conditions, it gives empty cells. Is there any way to solve this problem efficiently. Any help is appreciated.
Z = xlsread('DataXY.xlsx');
m = length(Z(:,1));
X = Z(:,1); Y = Z(:,2); T0 = 28/365;
%%% FSOLVE
f = @(a) [sum(a(2) + a(1) - Y - a(2) .* exp(a(3) .* (T0 - X)));...
sum((exp(a(3) .* (T0 - X)) - 1) .* (a(2) + a(1) - Y - a(2) .* exp(a(3) .* (T0 - X))));...
sum(a(2) .* exp(a(3) .* (T0 - X)) .* (T0 - X) .* (a(2) + a(1) - Y - a(2) .* exp(a(3) .* (T0 - X))));...
sum((a(2) + a(1) - Y - a(2) .* exp(a(3) .* (T0 - X))).^2) - (m.*a(4).^2)];
P1 = fsolve(f,[2 2.5 0.01 0.1]);
%%%VPASOLVE
syms a b c d
eq1 = sum(Y - a -b + b .* exp(c .* (T0 - X)));
eq2 = sum((exp(c .* (T0 - X))-1) .* (b + a - Y - b .* exp(c .* (T0 - X))));
eq3 = sum(b .* exp(c .* (T0 - X)) .* (T0 - X) .* (b + a -Y - b .* exp(c .* (T0 - X))));
eq4 = sum((b + a - Y - b .* exp(c .* (T0 - X))).^2) - (m.*d.^2);
P2 = vpasolve(eq1, eq2, eq3, eq4);
0 Comments
Accepted Answer
Matt J
on 3 Jun 2021
No, your equations don't have closed-form solutions. In any such situation, you will have to provide an accurate initial guess to get a reliable solution, assuming one exists.
5 Comments
Matt J
on 3 Jun 2021
Edited: Matt J
on 3 Jun 2021
For example, if you know that your a(i) are all bounded between 0 and 1, you can generate 50x50x50x50 grid arrays with ndgrid as below, and evaluate all your equations at all the grid points in a vectorized fashion
fn=@(q) reshape(q,1,1,1,1,[]);
X = fn(Z(:,1)); Y = fn(Z(:,2)); T0 = 28/365;
[A1,A2,A3,A4]=ndgrid(linspace(0,1,50));
whos A*
%Evaluate all equations at grid points
fn=@(q) abs(sum(q,4));
F1=fn( A2 + A1 - Y - A2 .* exp(A3 .* (T0 - X)) );
F2=fn( (exp(A3 .* (T0 - X)) - 1) .* (A2 + A1 - Y - A2 .* exp(A3 .* (T0 - X))) );
F3=fn( A2 .* exp(A3 .* (T0 - X)) .* (T0 - X) .* (A2+ A1 - Y - A2 .* exp(A3.* (T0 - X))) );
F4=fn((A2 + A1 - Y - a(2) .* exp(A3 .* (T0 - X))).^2) - (m.*A4.^2));
[fval,imin]=min(F1(:)+F2(:)+F3(:)+F4(:)); %compute minimizing grid location
a=[A1(imin) A2(imin) A3(imin) A4(imin)] %initial guess for FSOLVE
More Answers (0)
See Also
Categories
Find more on Mathematics and Optimization in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!