MATLAB Function (Solving an Error)

后端 未结 3 2041
走了就别回头了
走了就别回头了 2021-01-29 14:57

I have one file with the following code:

function fx=ff(x)
fx=x;

I have another file with the following code:

function g = Lapl         


        
3条回答
  •  臣服心动
    2021-01-29 15:04

    You can also use the TRAPZ function to perform trapezoidal numerical integration. Here is an example:

    %# parameters
    a = 0; b = 1;
    N = 100; s = 1;
    f = @(x) x;
    
    %# integration
    X = linspace(a,b,N);
    Y = f(X).*exp(-s*X);
    If = trapz(X,Y)        %# value returned: 0.26423
    
    %# plot
    area(X,Y, 'FaceColor',[.5 .8 .9], 'EdgeColor','b', 'LineWidth',2)
    grid on, set(gca, 'Layer','top', 'XLim',[a-0.5 b+0.5])
    title('$\int_0^1 f(x) e^{-sx} \,dx$', 'Interpreter','latex', 'FontSize',14)
    

    screenshot

提交回复
热议问题