필터 지우기
필터 지우기

what is the wrong wtih the “fsolve” function to solve the problem?

조회 수: 1 (최근 30일)
cheng sy
cheng sy 2015년 10월 10일
댓글: cheng sy 2015년 10월 28일
the figure is the lightning voltage,if the maxium amplitude of it is Um, the green line
crosses the two points:(t1,90%*Um) and (t2,30%*Um),and it intersect at x-axis and horizontal
line of Um。tf is called wave-front time,and the Tt is the half-tail time。Usuallly,we
suppose the voltage can express as the following equation(also double exponential equation):
u(t)=U*ζ*(exp(-a*t)-exp(-b*t)). Now, we know the tf,Tt and U(the maxium amplitude),
the ζ,a,and b to be solved. this question can be solved by the matlab function fsolve. i
have defined the following fuction in matlab:
%--------------------------------------------------------------------%
function Vc = imp_f(x,tf,Tt,U)
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
% X is the [a;β;ζ;t1;t2]
% a/β/ζ are the parameters in function :i(t)=U*ζ*(exp(-a*t)-exp(-β*t));
% t1/t2/Tt/tf:(t1,90%*Um) and (t2,30%*Um) have the same meaning in the previous figure ,U is voltage crest,kV;
Vc=[tf-(x(4)-x(5))/0.6; % tf=(x(4)-x(5))/0.6
0.3*U-x(3)*(exp(-x(1)*x(5))-exp(-x(2)*x(5))); % cross the point (t2,30%*Um)
0.9*U-x(3)*(exp(-x(1)*x(4))-exp(-x(2)*x(4))); % cross the point (t1,90%*Um)
0.5*U-x(3)*(exp(-x(1)*(Tt+1.5*x(5)-0.5*x(4)))-exp(-x(2)*(Tt+1.5*x(5)-0.5*x(4)))); %cross the point
(Tt+1.5*t2-0.5*t1,50%*Um)
U-x(3)*(exp(-x(1)*log(x(2)/x(1))/(x(2)-x(1)))-exp(-x(2)*log(x(2)/x(1))/(x(2)-x(1))))];
%cross the maximu value point
(log(β/a)/(β-a),Um)
end
then use the following code to find the answer:
%--------------------------------------------------------------------------
tf=1.2; %
Tt=50; %
U=1.0; %
x0=[1;1;1;1;1]; %初值;
[x,fval]=fsolve(@(x) imp_f(x,tf,Tt,U),x0); % Call solver
%---------------------------------------------------------------
MATLAB give the following wrong answer:
%---------------------------------------------------------------
Error using trustnleqn (line 28)
Objective function is returning undefined values at initial point. FSOLVE cannot continue.
Error in fsolve (line 376)
[x,FVAL,JACOB,EXITFLAG,OUTPUT,msgData]=...
Error in l_impluse (line 11)
[x,fval]=fsolve(@(x) imp_f(x,tf,Tt,U),x0); % Call solver
%--------------------------------------------------------------
and i donot know the reason? and how to solve the problem?

답변 (1개)

Walter Roberson
Walter Roberson 2015년 10월 10일
@(x) imp_f(x,tf,tt,U) references the non-existent variable tt . There is a Tt a few lines earlier in the code but not tt
  댓글 수: 5
Torsten
Torsten 2015년 10월 26일
You divide by x(2)-x(1) which is 0 at the start.
Furthermore, be careful that during iteration, x(2)/x(1) remains positive. Otherwise, log(x(2)/x(1)) will produce complex results.
Best wishes
Torsten.
cheng sy
cheng sy 2015년 10월 28일
thank you for your remind.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by