필터 지우기
필터 지우기

problem with input arguments

조회 수: 5 (최근 30일)
Gianmario
Gianmario 2014년 2월 24일
편집: Mischa Kim 2014년 2월 24일
i have a problem with the inputs of the following function. Tempo and t_media_filtrata_t are both previously developed and they are declared in the worhspace but when i run the function it compares an error message that say that input (tempo or t_media_filtrata_t) argument is undefined. Someone can help me? thank you
function[x]=residuo(x_ini,tempo,t_media_filtrata_t)
prompt={'potenza immessa(W):','profondità del foro(m)','passo di campionamento(s)','velocità di Darcy(m/s)','resistenza termica(m*K/W)'};
dlg_title='Input';
num_lines=1;
def={'3000','100','60','5*10^-10','0.1'};
answer=inputdlg(prompt,dlg_title,num_lines,def);
Q=str2num(answer{1});
H=str2num(answer{2});
deltaT=str2num(answer{3});
q=str2num(answer{4});
Rb=str2num(answer{5});
r_bw=0.075;
ro=2500;
c=3000;
row=1000;
cw=4186;
for index=1:length(t_media_filtrata_t)
T_calcolata(index)= (Q/H)./(4.*pi.*sqrt(x_ini(1).*x_ini(1))).*exp( (row.*cw.*q.*r_bw)./ (2.*x_ini(1) )).*quad(@(phi) (exp(-phi-(((r_bw.^2)./x_ini(1)) + ((r_bw.^2)./x_ini(1))).*(((row.*cw.*q).^2)./(16.*x_ini(1).*phi))).*(1./phi)),0,(((row.*cw.*q).^2).*tempo(index))./(4.*ro.*c.*x_ini(1)))+x_ini(2)+((Q/H)*Rb);
end
misfit=(T_calcolata-t_media_filtrata_t).^2;
residuo= sqrt((sum(misfit))/length(tempo));
opt = optimset ( 'Display' , 'iter','MaxIter' ,20 );
[x, fval, exitflag, output] = fminsearch ( residuo,x_ini,opt )
figure;
plot(tempo,t_media_filtrata_t,tempo,T_calcolata,'r');
title('segnale misuratao e calcolato per inversione');
end
  댓글 수: 2
Mischa Kim
Mischa Kim 2014년 2월 24일
편집: Mischa Kim 2014년 2월 24일
How and where from are you calling the function?
Gianmario
Gianmario 2014년 2월 24일
from the command window: [x]=residuo([1.5, 18],tempo,t_media_filtrata_t)

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

답변 (3개)

Iain
Iain 2014년 2월 24일
You need to supply those arguments to the function, by calling it like:
tempo_var_with_silly_long_name = 5; %use the real value, not what I've just came up with
t_media_filtrata_t = 42; %use the real value, not what I've just came up with
x_ini = 0;
x=residuo(x_ini, tempo_var_with_silly_long_name ,t_media_filtrata_t);
  댓글 수: 2
Gianmario
Gianmario 2014년 2월 24일
but both inputs are linear matrix developed by other function. In the previously function i put them into output. Not a nested but two distinct function
function [x,y]=first_function(a,b)
end
function [z]=second_function(x,y)
end
Iain
Iain 2014년 2월 24일
Check that the variables exist before calling residio?

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


Image Analyst
Image Analyst 2014년 2월 24일
It's a function that requires inputs so you can't just type F5 or click the green "run" triangle. You need to supply values for those inputs.

Mischa Kim
Mischa Kim 2014년 2월 24일
편집: Mischa Kim 2014년 2월 24일
If you execute the which command in the command window do you get
which tempo
tempo is a variable.
which t_media_filtrata_t
t_media_filtrata_t is a variable.
If not, then the variables are not declared in the workspace. In other words, if the variables are outputs of other functions, they need to be specified accordingly. E.g.
[tempo, t_media_filtrata_t] = my_func(arg1, arg2)
now you can call
[x] = residuo([1.5, 18],tempo,t_media_filtrata_t)
  댓글 수: 2
Gianmario
Gianmario 2014년 2월 24일
i tried it on the command window and it says that both of them are variables.
Mischa Kim
Mischa Kim 2014년 2월 24일
편집: Mischa Kim 2014년 2월 24일
Here you go...
  • Within the function, you call the same function, again, recursively. Is this what you are trying to do?
opt = optimset ( 'Display' , 'iter','MaxIter' ,20 );
[x, fval, exitflag, output] = fminsearch ( residuo,x_ini,opt )
  • And even if this is planned, you need to properly call the function with all of its input arguments.
  • Finally, you are using residuo also as a variable.
residuo = sqrt((sum(misfit))/length(tempo));

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

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by