problem with VPASOLVE and FSOLVE

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);

 Accepted Answer

Matt J
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

Thank you @Matt J. I understand that there is no closed-form solution available to this equation. The problem is that I don't have the initial conditions and the exact solution as well. Can you suggest to me what alternative Matlab function can be used here other than fsolve and vpasolve.
Since you only have 4 unknown variables, you can develop a, approximate initial guess by doing a discrete grid search, e.g., on a 100x100x100x100 grid of points. Your equations are very vectorizable, so this search should be very fast.
Thank you @Matt J for your humble reply again. Can you little bit elaborate on how to do discrete grid search. Maybe with some example or online literature.
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*
Name Size Bytes Class Attributes A1 50x50x50x50 50000000 double A2 50x50x50x50 50000000 double A3 50x50x50x50 50000000 double A4 50x50x50x50 50000000 double
%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
Thank you very much @Matt J. This is really appreciated. I learned this.

Sign in to comment.

More Answers (0)

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!