Report On Matlab Calculator

advertisement
CPE 521-APPLIED FUZZY LOGIC
HOMEWORK-I
INSTRUCTOR: Dr. POWSIRI KLINKHACHORN
WEST VIRGINIA UNIVERSITY
Submitted By:
Ajit Kumar Pandey
ajitp@csee.wvu.edu
WVU ID: 700594785
Contents
1.
2.
3.
4.
5.
6.
Introduction to Matlab Tool.
Introduction to Graphical User Interface.
About Graphical Calculator.
Working of GUI based Calculator.
Important Conclusions.
Reference books and Websites.
Introduction to Matlab Tool
MATLAB stands for Matrix Laboratory and was originally written
to provide easy access to matrix software development by the
LINPACK and EISPACK projects.
Matlab is a high-performance language for technical computing. It
integrates visualization and programming along with computation,
in an easy-to use environment where problems and solutions are
expressed in familiar mathematical notations.
Matlab features a family of application specific solutions called
toolboxes. Toolbox allows learning and applying specialized
technology. Toolboxes are comprehensive collections of Matlab
functions (M-files) that extend the Matlab environment to solve
particular classes of problems.
The figure the basic features of Matlab in a graphical manner.
The Matlab Programming is used along with user written functions
and in-built functions in Graphics, Computation and External
Interface.
The bottom most box list the collection of specialized functions in
some prominent fields.
Introduction to Graphical User Interface
Matlab provides a set of high level graphic routines. It implements
commonly used techniques for displaying data, graphs, and
animations. One can exert more precise control over the way Matlab
displays data using handle graphics.
Using Handle graphics, you can create menus, buttons, text boxes,
and other user interface devices.
One can build sophisticated user interfaces for any Matlab-based
application.
With Handle graphics one can add a GUI to any M-file or define his
own environment that starts whenever he begins a Matlab session.
Here is an example of GUI, one that I have designed.
Matlab Based Graphical Calculator:
About IDE & Graphical Calculator
The above figure shows a graphical calculator designed in Matlab 7.04
It has been developed using IDE in Matlab that is GUIDE, the
Graphical User interface Development Environment. This IDE provides
tool for creating GUI frames and coding in the related M-file.
The IDE provides a Layout Editor that looks like this:
We get this window by typing GUIDE at the MATLAB command
prompt (>>). There are various tools required to design a GUI. One can
find Pushbuttons, Text box, Static Text Box, List Box, Pop-up Menu,
Edit Box, etc. that are required to create any User Interface. There is a
window named Property Inspector using which one can set the various
behaviors of the elements present on the Layout Editor.
Graphical Calculator
After designing the layout, putting desired strings on the buttons/edit
boxes, and setting colors, the final calculator look like what’s there in
the figure below.
It includes the basic functions of a calculator like addition, subtraction,
multiplication, and division along with some function related operations
like inverse, square, square root, etc.
The clear button clears the previous result from the display box and sets
it empty. There is a select function pop-up menu that provides options
for sine, cosine, tangent and log calculations.
The above figure shows all the components that are provided
functioning when the program is run.
The bottom of the calculator shows a black colored button that can be
used for demo of the graphical plots that can be plotted during the
actual functioning of the calculator.
Functioning of GUI based Calculator
To add two numbers and subtract the third one, follow these steps:
Step I
: Press the first number…. it will appear in the display box.
Step II : Press the ‘+’ button.
Step III : Press the second number and then the ‘-’ button.
Step IV : Now press the third number.
The display should look like this:
Step V : Finally, press the’=’ button to see the result on the display
screen.
That’s it….this way you can do as many calculations as you want,
pushing ‘*’ and ‘/’ buttons for multiplication and division respectively.
The final result will always be displayed on the output display screen.
To calculate square root of a number
To calculate square root of a number, use the button ‘sqrt(x)’. This is
as same as the normal calculator.
Step1: Enter the number.
Step2: Press the ‘sqrt(x)’ button.
Step3: Press the equals’ button.
And you are done. The square of the number will be displayed on the
screen like this:
For example, the square root of 25 comes out to be 5 as we can see in the
above figures.
The Square of any number can be calculated in the similar way.
Follow the same steps and push ‘X^2’ button instead of ‘sqrt(x)’ and
after hitting ‘=’ button, you will get the desired result.
Trigonometric Calculations:
To calculate sine of a number, select ‘sine’ option from the pop-up
menu labeled ‘select function’ as shown below:
Then enter the number whose sine needs to be determined.
NOTE: Sine will calculate the value taking the number entered to be in
degree. So enter the degree value like sin 3°.
Then press the ‘=’ button to get the value.
The next figure displays the value of sin 3°.
The value for sin 3° is 0.052336 as shown above.
Similarly you can select ‘log’ option from the same pop-up menu to
calculate log10 of a number.
The figure is shown below:
Just select ‘log’ from the menu and press the number you want to
calculate log for.
After pressing ‘=’ button you will get the result.
So we get the value of log of base 10 for the number being entered.
Same way you can calculate Tangent of a number or Cosine of a
number.
You need to select Cosine or Tangent from the pop-up menu shown
above.
Plotting Graphs of Trigonometric functions:
Matlab provides Plot, stem, comet, mesh, etc commands that are used to
plot 2D and 3D graphs on the graph axes. The above calculator employs
some of these commands to plot graphs for sine, cosine, tangent, and
logarithmic functions.
To plot graph for sin(x) having one cycle on the graph (frequency=1),
you can follow the following set of steps:
Step I: Select sine from pop-up menu.
Step II: Select the frequency by pushing the appropriate button from 1
to 9.
Step III: Now press the plot button.
The figure above shows the plot for sine curves when its frequency is 10.
It also shows the value of sin 10° in the above display screen.
The frequency for the plot is indicated in the edit box next to static text
’Frequency =>’.
Similarly you can plot for cosine, log and tangent also.
The figure shows the value of tan 45 in the display window of the
calculator.
Important Conclusions:
This Graphical Calculator is developed using the IDE feature of the MATLAB version
7.04. The calculator demonstrates some basic features of a simple calculator and some
trigonometric functions are also being included to mimic the scientific version of a
calculator. Moreover plots of basic trigonometric functions and log function are also
being incorporated.
Shortcomings: This calculator requires the user must have the knowledge of how to use
its functions like, when to press ‘=’ button and when press ‘Clear’ button without which
he may get the erroneous results of some calculations. Also to start a plot he must enter
the desired frequency each time as the display screen contains the previous results that
can not be used for actual plotting. Ultimately, the calculator provides the user with the
needful.
Reference books and Websites:
Books referred:


MATLAB: Language of Technical Computing.
The Math Works Inc.
Getting started with MATLAB
Rudra Pratap.
Websites:




http://www.math.utah.edu/lab/ms/matlab/matlab.html
Gives link of a basic tutorials for mathematical calculations in Matlab.
http://www.math.ufl.edu/help/matlab-tutorial/matlab-tutorial.html#SEC5
http://www.math.siu.edu/matlab/tutorial2.pdf
This link gives access to Matlab programming, M-files, and Graphs Plotting.
http://csee.wvu.edu/classes/cpe520
This link is the course website for Cpe520 at the host csee.wvu.edu at WVU.
This provides a balanced comprehensive documental help for using almost
every feature of Matlab.
*******************************END******************************
Download