I’m trying to write m. file that would do the following if I enter this in the command window:
>> test
Enter the function: (s^2+6*s+9)/(s^3+2*s^2-s-2)
The Poles:
-2
-1
1
The Zeros:
-3
-3
The Result:
1/(3*exp(2*t)) - 2/exp(t) + (8*exp(t))/3
The Initial Value:
1
and here is my attempt: (of course, it doesn’t work)
function y = f(s)
y = input('Enter the function: ');
[n d] = numden(y);
zeros = solve(n);
poles = solve(d);
yt = ilaplace(y);
disp('The Poles:');
disp(poles);
disp('The Zeros:');
disp(zeros);
disp('The Result:');
disp(yt);
disp('The Initial Value:');
disp(f(0));
Functions in Matlab work like functions in most programming language: they expect a list of input parameters and return a list of output parameters:
In your example, the function
freturns the user input – is that what you want? Also, the input parameterxis never used and therefore useless. If you neither use the input parameter, nor the output parameter – then why use a function at all? You could use a Matlab script instead.In the function body you’re using the variable
func, which has been never defined. What value did you expect it to have? I guess you want to pass the user input to the functionnumden, which expects a numeric or symbolic matrix. You’ll have to convert the user input into something that is understood bynumden. Note that if you want to get the string entered by the user, you’ll have to use the Option's'withinput, otherwise the user input will be interpreted as a Matlab expression.