Attempted to access f(0); index must be a positive integer or logical

function [ w ] = trap_wfp610( n )
% Calculates the work done using numerical integration and the trapezoidal rule
% Detailed explanation goes here
h=(5*10^-2)/n;
a=0;
b=5*10^-2;
f=(5*(10^5)*a+10^5)*pi*(5*10^-2)^2
g=(5*(10^5)*b+10^5)*pi*(5*10^-2)^2
w=h/2*(f(a)+g(b))
end

 Accepted Answer

You need to create these two lines as anonymous functions:
f = @(a) (5*(10^5)*a+10^5)*pi*(5*10^-2)^2
g = @(b) (5*(10^5)*b+10^5)*pi*(5*10^-2)^2
and you won’t get that error.

More Answers (0)

Asked:

on 10 Dec 2014

Answered:

on 10 Dec 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!