problem with function call

12 次查看(过去 30 天)
sim_sup
sim_sup 2020-4-22
评论: sim_sup 2020-4-22
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 个)

Geoff Hayes
Geoff Hayes 2020-4-22
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 个评论
Geoff Hayes
Geoff Hayes 2020-4-22
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
sim_sup
sim_sup 2020-4-22
Dear Geoff,
Works perfect, tx for the kind help :-)
best regards
Andras

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

标签

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by