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

 採用された回答

Matt J
Matt J 2021 年 6 月 3 日

0 投票

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 件のコメント

Deepti Ranjan Majhi
Deepti Ranjan Majhi 2021 年 6 月 3 日
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.
Matt J
Matt J 2021 年 6 月 3 日
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.
Deepti Ranjan Majhi
Deepti Ranjan Majhi 2021 年 6 月 3 日
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.
Matt J
Matt J 2021 年 6 月 3 日
編集済み: Matt J 2021 年 6 月 3 日
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
Deepti Ranjan Majhi
Deepti Ranjan Majhi 2021 年 6 月 3 日
Thank you very much @Matt J. This is really appreciated. I learned this.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMathematics and Optimization についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by