Sunteți pe pagina 1din 4

%{

******************************************************
filename:week6_P7.m
programmername:SultanAlanjdi
datecreated:08/09/14
dateoflastrevision:08/13/14
detailsoftherevision:none
shortdescription:Differentiation,integrationandgraphingorplotting
thegraphs
*******************************************************
%}

clc,clear;

%programdescription:thisisintendedfortheuser
disp('ThisprogramwillDifferentiation,integrationandgraphingorplotting
thegraphsofthefunctionyouprovide.');

%listofvariablesusedwithashortdescription
%fisusedtostorethefunction
%derivative_funcisusedtostorethederivativeofthefunction
%int_funcisusedtostoretheintegrationofthefunction

%Variableinitialization
symsx;
flag=0;
keepLooping=1;
%Calculation
while(keepLooping)
choices=menu('Differentiation,Integration,andPlottingafunction'...
,'Enterafunction'...
,'Differentiation'...
,'Integration'...
,'Plotthefunction'...
,'Exit'...
);

switch(choices)

case1
f=input('Pleaseenterafunctioninasymbolicformat,forexample
(3*x^3+2*x^2),xisthevariable>>');
y=sym(f);
flag=1;

case2

if(flag)
nth=menu('Pleaseenterthenthrootofthederivativeforthe
function','1','2','3','4');
fprintf('Withannthrootof%0.0f,thederivativeoffunction
oneisequalto:\n',nth);
derivative_func=diff(f,nth);%Functionisusedtocalculate
thederivativebasedonthenthroot
pretty(derivative_func)%usedthefunctionprettytodisplayit
inaniceform
flag=1;
else
disp('***Mustenterthefunctionfirst')
end

case3
if(flag)
fprintf('Theintegrationofthefunctionis:\n')
int_func=int(f);%Functionisusedtocalculatetheintegral
pretty(int_func)%usedthefunctionprettytodisplayitinanice
form
flag=1;
else
disp('***Mustenterthefunctionfirst')
end

case4
if(flag)

fprintf('Thefunctionyouhavechoosenis:\n')
disp(f)
fprintf('Thederivativeofthefunctionyouhavechoosenis:\n')
disp(derivative_func)
fprintf('Theintegrationofthefunctionyouhavechoosenis:\n')
disp(int_func)
%Redisplayingthefunction,its'derivativeandits'
%integration

subplot(2,2,1)
ezplot(f);
title('Thefunction')
xlabel('xaxis')
ylabel('yaxis')

subplot(2,2,2)
ezplot(derivative_func);
title('Thederivativeofthefunction')
xlabel('xaxis')
ylabel('yaxis')

subplot(2,2,3)
ezplot(int_func);
title('Theintegrationofthefunction')
xlabel('xaxis')
ylabel('yaxis')

flag=1;
else
disp('***Mustenterthefunctionfirst')
end

case5

disp('Theprogramiscompleted,Thankyou')

break;

end
end
%Displayingtheresult

%samplerunappendedfromtheMatlab'sCommandWindow
%{
Samplerun1:
ThisprogramwillDifferentiation,integrationandgraphingorplottingthe
graphsofthefunctionyouprovide.
Pleaseenterafunctioninasymbolicformat,forexample(3*x^3+2*x^2),xis
thevariable>>3*x^4+2*x^2
Withannthrootof2,thederivativeoffunctiononeisequalto:
2
36x+4
Theintegrationofthefunctionis:
32
x(9x+10)

15
Thefunctionyouhavechoosenis:
3*x^4+2*x^2

Thederivativeofthefunctionyouhavechoosenis:
36*x^2+4

Theintegrationofthefunctionyouhavechoosenis:
(x^3*(9*x^2+10))/15

Theprogramiscompleted,Thankyou
Samplerun2bychoosingsecondoption:
ThisprogramwillDifferentiation,integrationandgraphingorplottingthe
graphsofthefunctionyouprovide.
***Mustenterthefunctionfirst
Samplerun3bychoosingthirdoption:
ThisprogramwillDifferentiation,integrationandgraphingorplottingthe
graphsofthefunctionyouprovide.
***Mustenterthefunctionfirst
Samplerun4bychoosingfourthoption:
ThisprogramwillDifferentiation,integrationandgraphingorplottingthe
graphsofthefunctionyouprovide.
***Mustenterthefunctionfirst

%}

S-ar putea să vă placă și