简体   繁体   English

matlab中没有足够的输入参数错误

[英]Not enough input arguments error in matlab

This is my matlab code , I got Not enough input argument error in line 2 and i don't know how to fix it.这是我的 matlab 代码,我在第 2 行出现了 Not enough input argument 错误,我不知道如何修复它。 Anyhelp ?有帮助吗? Thanks in advance .提前致谢 。

function [] = Integr1( F,a,b )
i = ((b - a)/500);
x = a;k = 0; n = 0;
while x <= b
    F1 = F(x);
    x = x + i;
    F2 = F(x);
   m = ((F1+F2)*i)/2;
    k = k +m;
end
k
x = a; e = 0; o = 0;
while x <= (b - 2*i)
    x = x + i;
    e = e + F(x);
    x = x + i;
    o = o + F(x);
end
n = (i/3)*(F(a) + F(b) + 2*o + 4*e)

This code performs integration by the trapezoidal rule.此代码通过梯形规则执行积分。 The last line of code gave it away.最后一行代码放弃了它。 Please do not just push the Play button in your MATLAB editor.不要只按 MATLAB 编辑器中的“播放”按钮。 Don't even think about it, and ignore that it's there.甚至不要考虑它,并忽略它在那里。 Instead, go into your Command Prompt, and you need to define the inputs that go into this function.相反,进入你的命令提示符,你需要定义进入这个函数的输入。 These inputs are:这些输入是:

  • F : A function you want to integrate: F :您要集成的功能:
  • a : The starting x point a : 起点x
  • b : The ending x point b : 终点x

BTW, your function will not do anything once you run it.顺便说一句,一旦你运行它,你的函数就不会做任何事情。 You probably want to return the integral result, and so you need to modify the first line of your code to this:您可能想要返回积分结果,因此您需要将代码的第一行修改为:

function n = Integr1( F,a,b )

The last line of code assigns n to be the area under the curve, and that's what you want to return.最后一行代码将n指定为曲线下的面积,这就是您想要返回的。

Now, let's define your parameters.现在,让我们定义您的参数。 A simple example for F is a linear function... something like: F一个简单示例是线性函数……类似于:

F = @(x) 2*x + 3;

This defines a function y = 2*x + 3 .这定义了一个函数y = 2*x + 3 Next define the starting and ending points:接下来定义起点和终点:

a = 1; b = 4;

I made them 1 and 4 respectively.我分别做了 1 和 4。 Now you can call the code:现在你可以调用代码:

out = Integr1(F, a, b);

out should contain the integral of y = 2*x + 3 from x = 1 to x = 4 . out应该包含y = 2*x + 3x = 1x = 4的积分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM