problem with VPASOLVE and FSOLVE

조회 수: 8 (최근 30일)
Deepti Ranjan Majhi
Deepti Ranjan Majhi 2021년 6월 3일
댓글: Deepti Ranjan Majhi 2021년 6월 3일
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일
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
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개)

카테고리

Help CenterFile Exchange에서 Mathematics and Optimization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by