problem with function call

9 views (last 30 days)
sim_sup
sim_sup on 22 Apr 2020
Commented: sim_sup on 22 Apr 2020
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

Answers (1)

Geoff Hayes
Geoff Hayes on 22 Apr 2020
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 Comments
Geoff Hayes
Geoff Hayes on 22 Apr 2020
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 on 22 Apr 2020
Dear Geoff,
Works perfect, tx for the kind help :-)
best regards
Andras

Sign in to comment.

Categories

Find more on MATLAB in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!