how to solve " Undefined function 'lt' for input arguments of type 'tf'. Error in ftfs (line 5) while (t < tf) ?"

3 Ansichten (letzte 30 Tage)
the function is :
function []= ftfs()
j = 1;
t = 0;
while (t < tf)
u(1,j+1) = u(1,j) - (lambda*a).*(u(2,j)-u(1,j));
u(N,j+1)= u(1,j+1);
u(2:(N-1),j+1) = u(2:(N-1),j) - (lambda*a).*(u(3:N,j)-u(2:(N-1),j));
t = t + dt;
j = j + 1;
end
plot(x,u(:,i),'m-..-')
end
I am calling this function in this program :
a = input('Insert the value of a: ');
CFL = input('Insert the value of CFL: ');
tf = input('Insert final time : '); %final time
dx = input('Insert the value of dx: ');
dt = (CFL * dx)/ abs(a);
lambda = (dt/dx)
N = input('Insert the value of N: ');
x = linspace(-1,1,N);
%choose test case:
tc= input('choose test case number : ');
if tc == 1
u(:,1)= -sin(pi.*x)
end
plot(x,u(:,1),'k')
hold on
ftfs();
hold on

Akzeptierte Antwort

OCDER
OCDER am 11 Dez. 2017
Bearbeitet: OCDER am 11 Dez. 2017
The problem lies in understanding the scope of each variable used in Matlab. Here's a read on that: http://matlab.izmiran.ru/help/techdoc/matlab_prog/ch12_nd5.html
Each function is like a new workspace, where it does NOT see the variables made OUTSIDE the function, unless passed as an input, used by a nested function, or used as global variables.
You did not specify what "tf" is in ftfs. So this while loop has no idea what the conditions are. This is what the function is seeing:
while (t < tf) translates to:
while t is less than an undefined function called tf (or a transfer function with no inputs)
To fix this, you need ftfs to take inputs.
function [] = ftfs(a, CFL, tf, dt, lambda, N, x, u)
And then you need to pass the variables into the function when you call ftfs.
hold on
ftfs(a, CFL, tf, dt, lambda, N, x, u);
hold on
Note that you will get an error if tc is unequal to 1, since then u is undefined. Also, your ftfs function does not know what i is, so you'll get another error.
  6 Kommentare

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by