Umal-qura university


Double Precision Arithmetic



Yüklə 0,73 Mb.
səhifə3/30
tarix23.12.2023
ölçüsü0,73 Mb.
#156716
1   2   3   4   5   6   7   8   9   ...   30
Signal and Systems Manual - v2full

Double Precision Arithmetic

All arithmetic is done to double precision, which for 32‐bit machines means to about 16 decimal


digits of accuracy. Normally the results will be displayed in a shorter form.
>> a = sqrt(2)
a =
1.4142
>> format long, b=sqrt(2)
b =
1.41421356237310
>> format short



      1. Command-Line Editing

The arrow keys allow "command‐line editing," which cuts down on the amount of typing required, and allows easy error correction. Press the "up" arrow, and add "/2." What will this produce?


>> 2+3*4^2/2
Parentheses may be used to group terms, or to make them more readable. For example: >> (2 + 3*4^2)/2
generates ans = 25.

      1. Built-In Mathematical Functions

MATLAB has a platter of built‐in functions for mathematical and scientific computations. Here is a summary of relevant functions.




Function Meaning Example
======================================================
sin sine sin(pi) = 0.0
cos cosine cos(pi) = 1.0
tan tangent tan(pi/4) = 1.0
asin arcsine asin(pi/2)= 1.0
acos arccosine acos(pi/2)= 0.0
atan arctangent atan(pi/4)= 1.0
exp exponential exp(1.0) = 2.7183 log natural logarithm log(2.7183) = 1.0 log10 logarithm base 10 log10(100.0) = 2.0
======================================================
The arguments to trigonometric functions are given in radians.


Example: Let's verify that
sin(x)^2 + cos(x)^2 = 1.0
for arbitrary x. The MATLAB code is:
>> x = pi/3;
>> sin(x)^2 + cos(x)^2 ‐ 1.0
ans =

0


    1. TIMING COMMANDS

Timing functions may be required to determine the time taken by a command to execute or an operation to complete. Several commands are available to accomplish it:





      1. Clock

CLOCK returns Current date and time as date vector. CLOCK returns a six element date vector containing the current time and date in decimal form:


CLOCK = [year month day hour minute seconds]
The first five elements are integers. The second’s element is accurate to several digits beyond the decimal point. FIX(CLOCK) rounds to integer display format.



      1. Etime

ETIME Elapsed time.


ETIME(T1,T0) returns the time in seconds that has elapsed between vectors T1 and T0. The two vectors must be six elements long, in the format returned by CLOCK:
T = [Year Month Day Hour Minute Second]
Time differences over many orders of magnitude are computed accurately. The result can be thousands of seconds if T1 and T0 differ in their first five components or small fractions of seconds if the first five components are equal.
t0 = clock; operation etime(clock,t0)



      1. Tic Toc

TIC Start a stopwatch timer. The sequence of commands


TIC, operation, TOC
prints the number of seconds required for the operation.


    1. INPUT & DISPLAY




      1. INPUT

INPUT prompts for user input.
R = INPUT('How many apples')
gives the user the prompt in the text string and then waits for input from the keyboard. The input can be any MATLAB expression, which is evaluated, using the variables in the current workspace, and the result returned in R. If the user presses the return key without entering anything, INPUT returns an empty matrix.



Yüklə 0,73 Mb.

Dostları ilə paylaş:
1   2   3   4   5   6   7   8   9   ...   30




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©genderi.org 2024
rəhbərliyinə müraciət

    Ana səhifə