![]() |
编写可解决laplace和其他问题的.m类
我正在尝试写m。如果在命令窗口中输入以下内容,它将执行以下操作:
>> 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 这是我的尝试:(当然,它不起作用) function y = f(s) y = input('Enter the function: '); [nd] = 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)); [B]回答:[/B] Matlab中的函数与大多数编程语言中的函数一样工作:它们期望输入参数列表并返回输出参数列表: function [out1 out2] = myFunc(in1, in2) 在您的示例中,函数f返回用户输入-这就是您想要的吗?同样,输入参数x永远不会使用,因此是无用的。如果既不使用输入参数,也不使用输出参数-那么为什么要完全使用函数?您可以改用Matlab脚本。 在函数主体中,您使用的变量func从未定义。您期望它具有什么价值?我猜您想将用户输入传递给函数numden ,该函数需要一个数字或符号矩阵。您必须将用户输入转换为numden可以理解的numden 。请注意,如果你想获得用户输入的字符串,你必须使用选项's'与input ,否则用户输入将被解释为一个Matlab表达。 [url=https://stackoverflow.com/questions/5189538]更多&回答...[/url] |
所有时间均为北京时间。现在的时间是 04:52。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.