problem with VPASOLVE and FSOLVE

7 次查看(过去 30 天)
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
Thank you very much @Matt J. This is really appreciated. I learned this.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Equation Solving 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by