Undefined function 'int' for input arguments of type 'double'.
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
James Tursa
on 6 Jul 2013
Edited: James Tursa
on 6 Jul 2013
First thing you should do is rename your max and min variables to something else. max and min are built-in MATLAB functions. If you shadow them with your variables you may end up breaking some other built-in functions that you happen to call that need the max or min functions.
Second thing you should do is edit your question so that the code is formatted with the "{}Code" button. This makes it easier for others to read.
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.
dreamsloppy
on 7 Jul 2013
Accepted Answer
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.
Categories
Find more on Numeric Solvers in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!