problem with function call

Dear Community,
I'm a newbie and wanted to test a function, but got stacked. Why this attached small program does not work? Its certainly something small bug here, but this is a big piece of rock for me.
tx in advance
Andras

回答(1 个)

sim_sup - it is always a good idea to include the full error message when posting your code...else we can only guess at the errors. For example, is the error
Function definitions are not permitted in this context.
because you have defined functions within your script (you can't do this for older versions of MATLAB)? If so, then just put the script part of the code within the function that this is the name of the file
function InvLapTest
%
% This routine tests the numerical inverse Laplace method of Den Iseger.
%
tser = ( .1 : .1 : 1.9 ) ;
% yser = ones(1,19) ;
yser = DenIseger( LTF , tser ) ;
end
Or, is the error
Error using InvLapTest>LTF (line 57)
Not enough input arguments.
because of how you call LTF without passing any input parameters?
yser = DenIseger( LTF , tser ) ;
The function signature for LTF is
function fs = LTF(s)
so you need to pass in a scalar (?) input parameter to this function like
yser = DenIseger( LTF(42) , tser ) ;
The input 42 is just an example...I have no idea what should be passed into this function.
The next error (assuming 42 is used) is
Subscript indices must either be real positive integers or logicals.
Error in InvLapTest>DenIseger (line 42)
ft = real(Lf(s)) ;
because s is an 8x153 array of imaginary numbers. Lf is a scalar but even if it were an array, you would get the same error (and probably others too). I recommend that you use the MATLABN debugger to trouble shoot your code.

3 个评论

Hi Geoff,
Sorry for all the silliness, I'm completely new here, I've just registered, plus newbie also in Matlab. You're right I should have included the error message, it was the second one, i.e. not enough input arguments.
I'vs seen this routine in the attached paper, and I thought I'll test it. My simple function is (1-Exp(-s))/s, which should give the result functiion 1(t-1) in the time series range timser if I'm right. I also tried the debugger, but it did not even let me enter into the routine, so that's why I asked for help. s should be indeed a complex number or array. Pls. have one more look, maybe you can figure out what I do wrong here.
Tx in advance,
best regards
Andras
Andras - is the first parameter of DenIseger supposed to be a function? If so, then try
tser = ( .1 : .1 : 1.9 ) ; ;
yser = DenIseger( @LTF , tser ) ; % <--- add the @ symbol to denote function
This may mean that the LTF function will need to change as well so that you do element-wise division
function fs = LTF(s)
%
fs = ( 1.0 - exp(-s) ) ./ s ; % <---- use ./ for element-wise division
%
end
Dear Geoff,
Works perfect, tx for the kind help :-)
best regards
Andras

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 MATLAB 的更多信息

产品

版本

R2020a

标签

提问:

2020-4-22

评论:

2020-4-22

Community Treasure Hunt

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

Start Hunting!

Translated by