matlab中没有足够的输入参数错误 [英] Not enough input arguments error in matlab

查看:415
本文介绍了matlab中没有足够的输入参数错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的matlab代码,我没有足够的输入参数错误在第2行,我不知道如何解决它。 Anyhelp?

 函数[] = Integr1(F,a,b)
i =((b - a )/ 500);
x = a; k = 0; n = 0;
,而x <= b
F1 = F(x);
x = x + i;
F2 = F(x);
m =((F1 + F2)* i)/ 2;
k = k + m;
结束
k
x = a; e = 0; o = 0;
,而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)


解决方案

这段代码通过梯形法则执行整合。最后一行代码将其发送出去。请不要在MATLAB编辑器中按下Play按钮。甚至不要去想它,而忽略它在那里。相反,进入你的命令提示符,你需要定义进入这个函数的输入。这些输入是:


  • F :您想要集成的函数:

  • a :起点 x

  • b :结尾 x



顺便说一句,一旦你运行它,你的函数将不会执行任何操作。您可能想返回整数结果,因此您需要将代码的第一行修改为:

  function n = Integr1(F,a,b)

最后一行代码将 n 赋值为曲线下方的区域,这就是你想要返回的结果。



现在,我们来定义你的参数。 F 的一个简单示例是一个线性函数...类似于:

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

定义了一个函数 y = 2 * x + 3 。接下来定义出发点和终点:

  a = 1; b = 4; 

我分别给出了1和4。现在你可以调用代码:

  out = Integr1(F,a,b); 

out 应该包含 y = 2 * x + 3 x = 1 x = 4


This is my matlab code , I got Not enough input argument error in line 2 and i don't know how to fix it. 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. 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:
  • a: The starting x point
  • b: The ending x point

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.

Now, let's define your parameters. A simple example for F is a linear function... something like:

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

This defines a function y = 2*x + 3. Next define the starting and ending points:

a = 1; b = 4;

I made them 1 and 4 respectively. 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.

这篇关于matlab中没有足够的输入参数错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆