problem with function call

조회 수: 9 (최근 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