Undefined function 'int' for input arguments of type 'double'.
8 views (last 30 days)
Show older comments
since im new to this matlab, im learning some calculation about the multi-segment trapezoidal rule using matlab so im having this question, and these are my codes
disp('This is a programme that evaluate the following function by multiple segment trapezoidal rule.')
disp('f(x)= 1/(1+x^2)')
min = input('Please enter a minimum boundary for the function above : ');
max = input('Please enter a maximum boundary for the function above : ');
while 1
seg = input('Please enter the number of segment you wish to : ');
if seg > 0 && rem(seg,1)== 0
break;
end
disp('Invalid input, please try it again!')
end
h = (max-min)/seg;
x = min:h:max;
y = 1./(1+x.^2);
area = 0;
for
i = 1:((max-min)/h)
area = area + 0.5*h*(y(1,i)+y(1,i+1));
end
x1 = min:0.001:max;
y1 = 1./(1+x1.^2);
area1 = trapz(x1,y1);
plot(x,y,x1,y1);
grid on
hold on
xlabel('X-axis')
ylabel('Y-axis')
legend('Conventional', 'Built-in')
for i = 1:( ((max-min)/h) + 1 )
plot([x(1,i) x(1,i)],[0 y(1,i)]);
end
area2 = int(1./(1+x.^2),min,max);
compare = (area/area1)*100;
fprintf('\nThe calculated area by using integration method is %g.', int(area2));
fprintf('\nThe calculated area by using conventional method is %g.', area);
fprintf('\nThe calculated area by using built-in function is %g.', area1);
fprintf('\nThe percentage error between built-in function and conventional method is %g%',compare);
hold off
i dont know what happen srsly and thx for advance for helping me solving this :D
3 Comments
dpb
on 6 Jul 2013
And when you do add the code formatting be sure it applies to the whole section...at least w/ the 'MATLAB code' tag a blank line terminates the style and reverts back to word wrap. :(
Also, delete anything that isn't mandatory to the problem -- for a case such as your title, best would be to cut 'n paste the error message in its entirety from the command window and then add what (minimal) additional code is needed for readers to see the context.
As it is, you're expecting somebody to either run your code or try to find where the error might be -- that's simply expecting too much from a volunteer at best or just simply rude at worst.
Accepted Answer
Walter Roberson
on 7 Jul 2013
You are attempting to use
int(1./(1+x.^2),min,max);
where x is already defined numerically. That is an attempt to do a numeric integration of a vector of values, but such an integration would not use a min or max. Providing a min and max would be something you would do for a symbolic integration.
If you have the symbolic toolbox and you want to do a symbolic integration, then you could use
int( '1/(1+x^2)', min, max);
or
syms X
int( 1./(1+X.^2), min, max);
Alternately you could ask to use the MATLAB numeric integration routines such as integral() or quadgk(). For that you would use something like
integral( @(X) 1./(1+X.^2), [min, max]);
0 Comments
More Answers (1)
the cyclist
on 6 Jul 2013
It looks from the context that int() here is the built-in function, from the Symbolic Math Toolbox, for symbolic integration. I am guessing that you don't have the Symbolic Math Toolbox, or maybe that you accidentally redefined int() to be something else (as James Tursa warned you about).
If you type
>> which int
you can see what MATLAB will try to call, if anything, when you use the int() function.
The ver command
>> ver
will tell you what toolboxes you have installed.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!