开发者

Writing .m class that solve laplace and other stuff

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 doe开发者_如何学Gosn'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:

function [out1 out2] = myFunc(in1, in2)

In your example, the function f returns the user input - is that what you want? Also, the input parameter x is 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 function numden, which expects a numeric or symbolic matrix. You'll have to convert the user input into something that is understood by numden. Note that if you want to get the string entered by the user, you'll have to use the Option 's' with input, otherwise the user input will be interpreted as a Matlab expression.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜