Example for the simple function in Matlab

%Let us discuss functions in Matlab with the simple example
% We know the formula for area of the circle is a=pi * r^2.
%Let  us write a function for this.

areacircmain.m



clc;
clear all;

radius = input('Enter the radus of the circle:');
ac=areacir(radius);

fprintf('Area of the circle with radius %.1f is %.1f\n', radius,ac);



areacir.m


function out=areacir(radius)
out=pi*radius^2;
end


output:


Enter the radus of the circle:5.2
Area of the circle with radius 5.2 is 84.9



Comments