Not enough input arguments error in matlab

前端 未结 1 1130
执念已碎
执念已碎 2021-01-23 19:09

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         


        
相关标签:
1条回答
  • 2021-01-23 19:17

    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.

    0 讨论(0)
提交回复
热议问题