Azzera filtri
Azzera filtri

problem with input arguments

5 visualizzazioni (ultimi 30 giorni)
Gianmario
Gianmario il 24 Feb 2014
Modificato: Mischa Kim il 24 Feb 2014
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 Commenti
Mischa Kim
Mischa Kim il 24 Feb 2014
Modificato: Mischa Kim il 24 Feb 2014
How and where from are you calling the function?
Gianmario
Gianmario il 24 Feb 2014
from the command window: [x]=residuo([1.5, 18],tempo,t_media_filtrata_t)

Accedi per commentare.

Risposte (3)

Iain
Iain il 24 Feb 2014
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 Commenti
Gianmario
Gianmario il 24 Feb 2014
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 il 24 Feb 2014
Check that the variables exist before calling residio?

Accedi per commentare.


Image Analyst
Image Analyst il 24 Feb 2014
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 il 24 Feb 2014
Modificato: Mischa Kim il 24 Feb 2014
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 Commenti
Gianmario
Gianmario il 24 Feb 2014
i tried it on the command window and it says that both of them are variables.
Mischa Kim
Mischa Kim il 24 Feb 2014
Modificato: Mischa Kim il 24 Feb 2014
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));

Accedi per commentare.

Categorie

Scopri di più su Environment and Settings in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by