fsolve + fminbnd combination... Problem !

Good evening to everybody. My problem is the following:
I want to solve a non-linear equation G(r)-(t-texp)=0 for the variable r with the following complications:
- r is in the upper limit of a definite integral of the integrand F(x).
-"texp" is a 1x10 array experimental points.
- t, which is another variable, are the minimums of another function H defined itself by G, H[t, G(r)].
I am not sure about the combination of algorithms that I must use. I have tried this scheme:
x0=ones(1,10)
rteor=@(r,t) fsolve(integral(G(x),1,r)-(t-texp),x0);
t = fminbnd(@(r,t) H,lb,up);
, but it does not work. I am almost sure fsolve is not well written. I have tried to make combinations with arrayfun inside fsolve, but with no success. I think it is a problem of dimensions and/or declaring variables. Can anybody help me please?
Thanks !!!

댓글 수: 2

Matt J
Matt J 2018년 10월 5일
편집: Matt J 2018년 10월 5일
So r is a scalar and t is a function of r through the equation
t(r) = argmin_z H(z,G(r) )
That means you have 10 equations in one unknown, r. How do you expect to satisfy 10 different equations with only 1 degree of freedom?
Or, do you mean you are looking for 10 different r(i), corresponding to each texp(i) separately?
Sergio Quesada
Sergio Quesada 2018년 10월 6일
편집: Sergio Quesada 2018년 10월 6일
Thank you for your answer, Matt. Yes, r is an scalar, and for each value of r, I want 10 different solutions G(r) - (texp-t) = 0, to be solve, each one for each value of texp. I call these solutions "rteor". I am trying this now:
rteor = @(r,t) fsolve(@(r) arrayfun (@(T) integral(F,1,r)-(T-t),texp), x0)
t = fminbnd(H(r,t),6e-3,t1-5e-5,options);
, with no results

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

답변 (1개)

Matt J
Matt J 2018년 10월 5일
편집: Matt J 2018년 10월 5일

0 개 추천

This might be what you want.
G=@(r) integral( @F,1,r);
t=@(r) fminbnd(@(z) H(z,G(r)),lb,up);
for i=1:10
r_solution(i) = fzero(@(r) G(r)-(t(r)-texp(i)) , r0 );
end

댓글 수: 11

Sergio Quesada
Sergio Quesada 2018년 10월 6일
편집: Sergio Quesada 2018년 10월 6일
Thank you so much, Matt...
I have tried your lines. This is my complete code:
%Previous definition of scalars
F=@(x) FC.*exp(-(V.*a)./(30.*x.*log(x))); % integrand
part=1e-3;
L=@(r) 1:part:r;
me=@(r) arrayfun(F,L(r));ue=@(r) F(max(L(r)));
Int=@(r) part.*(sum(me(r))-(ue(r)./2));
%Trapezoid integration to reduce calculus time
inpts=(1+(5.*((texp-t0).^0.25))).*ones(1,10);
for i=1:10
r_teor(i) = fzero(@(r) Int(r)-(t(r)-texp(i)), inpts);
end
Itotal=@(i) (FD./FC).*(rteor(i).*exp((V.*a)./(30.*rteor(i).*log(rteor(i)))))+Io./((rteor(i)).^4);
SumError=@(i) sum((Itotal(i)-Iexp).^2); %Iexp are also 1x10
%SumError is H, the function to find minimums
t=@(i) fminbnd(@(i) SumError(i),6e-3,t1-5e-5,options);
, and it gives the following error:
Error using fzero (line 433)
Second argument must be a scalar or vector of length 2.
Error in ampliando_integral_definitivo_6 (line 12)
r_teor(i) = fzero(@(r) Int(r)-(t(r)-texp(i)), inpts);
Hope you know how to avoid it... Thank you again !!
Matt J
Matt J 2018년 10월 6일
편집: Matt J 2018년 10월 6일
Yes, the second argument of fzero must be a vector of length 2 or a scalar. However, inpts is length 10. What is inpts and what is your rationale for passing it to fzero?
Sergio Quesada
Sergio Quesada 2018년 10월 6일
편집: Sergio Quesada 2018년 10월 6일
Inpts are my initial points for fzero. I want them to be given by a formula. This is now my script:
nombre='C2';t0=6.00E-3;FC=4.24E-1;a=6.05;FD=8.17E-4;Io=15.53;V=25; % Parámetros de inicio
fID=fopen('Para_Leer_C2_2219_ptos.txt','r');% Nombre de archivo de datos experimentales
Columnexpi=1;Columnexpf=10; % # de filas inicial y final de datos experimentales
formatSpec='%f %f'; sizeSpec=[2,Inf]; % 2 columnas separados por un espacio y con '.' como separador
datos=fscanf(fID,formatSpec,sizeSpec); close('all');N=Columnexpf-Columnexpi+1;
texp=datos(1, Columnexpi:Columnexpf);Iexp=datos(2, Columnexpi:Columnexpf); t1=texp(1);
F=@(x) FC.*exp(-(V.*a)./(30.*x.*log(x))); part=1e-3;
L=@(r) 1:part:r;
me=@(r) arrayfun(F,L(r));ue=@(r) F(max(L(r)));
Int=@(r) part.*(sum(me(r))-(ue(r)./2));
options = optimset('Display','iter','TolX',1e-4,'PlotFcns','@optimplotx');
for i=1:N
inpts=(1+(5.*((texp(i)-t0).^0.25)));
r_teor=@(i) fsolve(Int(r)-(t(i)-texp(i)), inpts(i));
Ifar=@(i)(FD./FC).*(r_teor(i).*exp((V.*a)./(30.*r_teor(i).*log(r_teor(i)))));
Itrans=@(i) Io./((r_teor(i)).^4);
Itotal=@(i) Ifar(i)+Itrans(i);
SumError=@(i) sum((Itotal(i)-Iexp).^2);
t= fminbnd(SumError,6e-3,t1-5e-5,options);
end
, giving:
Undefined function 'functions' for input arguments of type 'inline'.
Thank you for your help !!
Sergio Quesada
Sergio Quesada 2018년 10월 8일
편집: Sergio Quesada 2018년 10월 8일
Now I am on this point:
nombre='C2';t0=6.00E-3;FC=4.24E-1;a=6.05;FD=8.17E-4;Io=15.53;V=25;
fID=fopen('Para_Leer_C2_2219_ptos.txt','r');
Columnexpi=1;Columnexpf=10;
formatSpec='%f %f'; sizeSpec=[2,Inf];
datos=fscanf(fID,formatSpec,sizeSpec); close('all');N=Columnexpf-Columnexpi+1;
texp=datos(1, Columnexpi:Columnexpf);Iexp=datos(2, Columnexpi:Columnexpf); t1=texp(1);
F=@(x) FC.*exp(-(V.*a)./(30.*x.*log(x))); part=1e-3;
L=@(r) 1:part:r;
me=@(r) arrayfun(F,L(r));ue=@(r) F(max(L(r)));
Int=@(r) part.*(sum(me(r))-(ue(r)./2));
for i=1:N
inpts=@(i) (1+(5.*((texp(i)-t0).^0.25)));
options = optimoptions('fsolve','Display','none');
r_teor=@(i) fsolve(Int(r)-(t(i)-texp(i)), inpts(i));
Ifar=@(i)(FD./FC).*(r_teor(i).*exp((V.*a)./(30.*r_teor(i).*log(r_teor(i)))));
Itrans=@(i) Io./((r_teor(i)).^4);
Itotal=@(i) Ifar(i)+Itrans(i);
SumError=@(i) sum((Itotal(i)-Iexp).^2);
options = optimset('Display','iter','TolX',1e-4,'PlotFcns','@optimplotx');
t= fminbnd(SumError(i),6e-3,t1-5e-5,options);
end
, and it says:
Undefined function or variable 'r'.
Error in program>@(i)fsolve(Int(r)-(t(i)-texp(i)),inpts(i))
I have tried to write syms r above, and then it says:
Error using : (line 38)
Unable to compute number of steps from 1 to r by 1/1000.
Torsten
Torsten 2018년 10월 8일
편집: Torsten 2018년 10월 8일
r_teor=@(i) fsolve(@(r)Int(r)-(t(i)-texp(i)), inpts(i));
But where is t(i) ?
A few lines below
t= fminbnd(SumError(i),6e-3,t1-5e-5,options);
Torsten
Torsten 2018년 10월 8일
편집: Torsten 2018년 10월 8일
Below is too late for fsolve ...
Sergio Quesada
Sergio Quesada 2018년 10월 8일
Yes, that's exactly my problem. I can change i(t) to be defined at the beggining of the for-end, but in that case SumError(i) has not been defined before... And if I take SumError to the beggining, then r_teor(i) has not been defined...
Plase, tell me that you know how to solve it !!
Matt J
Matt J 2018년 10월 9일
편집: Matt J 2018년 10월 9일
You need to restate your problem (in equation form). In the beginning, you said that t was a function of r (not r_teor). Now, you've changed your mind and the thing you are trying to solve is very muddled.
In any case, you will not be able to use fsolve for this. Your functions is clearly non-differentiable.
Sergio Quesada
Sergio Quesada 2018년 10월 9일
편집: Sergio Quesada 2018년 10월 9일
Yes, Matt. I am continous changing the program because I am trying to solve it. The problem is not muddled at all:
1- I have a collection of experimental points (texp, Iexp) that I want to fit.
2 - The equation I have is not I(t), but I[r_teor(t)], where r_teor(t) is in the form t(r_teor), being "r_teor" in an upper integration limit.
As simple as that. This is my last code tried:
nombre='C2';t0=6.00E-3;FC=4.24E-1;a=6.05;FD=8.17E-4;Io=15.53;V=25;
fID=fopen('Para_Leer_C2_2219_ptos.txt','r');
Columnexpi=1;Columnexpf=10;
formatSpec='%f %f'; sizeSpec=[2,Inf];
datos=fscanf(fID,formatSpec,sizeSpec); close('all');N=Columnexpf-Columnexpi+1;
texp=datos(1, Columnexpi:Columnexpf);Iexp=datos(2, Columnexpi:Columnexpf); t1=texp(1);
F=@(x) FC.*exp(-(V.*a)./(30.*x.*log(x))); part=1e-3;
for i=1:N
t=@(i) (1+(5.*((texp(i)-t0).^0.25)))
r_teor=@(i) fsolve(Int(r)-(t(i)-texp(i)), inpts(i),options);
L=@(r) 1:part:rteor(i);
me=@(r) arrayfun(F,L(r)); ue=@(r) F(max(L(r)));
Int=@(r) part.*(sum(me(r))-(ue(r)./2));
options = optimoptions('fsolve','Display','none');
Ifar=@(i)(FD./FC).*(r_teor(i).*exp((V.*a)./(30.*r_teor(i).*log(r_teor(i)))));
Itrans=@(i) Io./((r_teor(i)).^4);
Itotal=@(i) Ifar(i)+Itrans(i);
SumError=@(i) sum((Itotal(i)-Iexp).^2);
options = optimset('Display','iter','TolX',1e-4,'PlotFcns','@optimplotx');
t= fminbnd(SumError(i),6e-3,t1-5e-5,options);
end
Torsten
Torsten 2018년 10월 9일
And you claim that
2 - The equation I have is not I(t), but I[r_teor(t)], where r_teor(t) is in the form t(r_teor), being "r_teor" in an upper integration limit.
is not muddled ? Nobody is able to understand what you write here.

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

카테고리

도움말 센터File Exchange에서 File Operations에 대해 자세히 알아보기

질문:

2018년 10월 5일

댓글:

2018년 10월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by