Schweitzer Fachinformationen
Wenn es um professionelles Wissen geht, ist Schweitzer Fachinformationen wegweisend. Kunden aus Recht und Beratung sowie Unternehmen, öffentliche Verwaltungen und Bibliotheken erhalten komplette Lösungen zum Beschaffen, Verwalten und Nutzen von digitalen und gedruckten Medien.
MATLAB is a high-level software package with many built-in functions that make the learning of numerical methods much easier and more interesting. In this section, we will introduce some basic operations that will enable you to learn the software and build your own programs for problem solving. In the workstation environment, you type "matlab" to start the program, while in the PC environment, you simply double-click the MATLAB icon.
Once you start the MATLAB program, a Command window will open with the MATLAB prompt ». On the command line, you can type MATLAB commands, functions together with their input/output arguments, the names of script files containing a block of statements to be executed at a time or functions defined by users. The MATLAB program files must have the extension name ***.m to be executed in the MATLAB environment. If you want to create a new M-file or edit an existing file, you click File/New/M-file or File/Open in the top left corner of the main menu, find/select/load the file by double-clicking it, and then begin editing it in the Editor window. If the path of the file you want to run is not listed in the MATLAB search path, the file name will not be recognized by MATLAB. In such cases, you need to add the path to the MATLAB-path list by clicking the menu 'Set_Path' in the Command window, clicking the 'Add_Folder' button, browsing/clicking the folder name and finally clicking the SAVE button and the Close button. The lookfor command is available to help you find the MATLAB commands/functions that are related with a job you want to be done. The help command helps you know the usage of a particular command/function. You may type directly in the Command window
>lookfor repeat or >help for
to find the MATLAB commands in connection with 'repeat' or to find information about the 'for loop'
MATLAB remembers all input data in a session (anything entered through direct keyboard input or running a script file) until the command ' clear()' is given or you exit MATLAB.
clear()
One of the many features of MATLAB is that it enables us to deal with the vectors/matrices in the same way as scalars. For instance, to input the matrices/vectors,
type the following statements in the MATLAB Command window:
>A=[1 2 3;4 5 6]
A= 1 2 3
4 5 6
>B=[3;-2;1]; %put the semicolon at the end of the statement to suppress the result printout onto the screen
>C=[1 -2 3 -4]
At the end of the statement, press <Enter> key if you want to check the result of executing the statement immediately. Otherwise, type a semicolon ';' before pressing <Enter> key so that the Command window will not be overloaded by a long display of results.
MATLAB can handle two types of data files. One is the binary format mat-files named ***.mat. This kind of files can preserve the values of more than one variable, but will be handled only in the MATLAB environment and cannot be shared with other programming environments. The other is the ASCII dat-files named ***.txt, which can be shared with other programming environments, but preserve the values of only one variable.
Beneath are a few sample statements for storing some data into a mat-file in the current directory and reading the data back from the mat-file.
>save ABC A B C %store the values of A,B,C into the file 'ABC.mat'
>clear A C %clear the memory of MATLAB about A,C
>A %what is the value of A?
Undefined function or variable 'A'
>load ABC A C %read the values of A,C from the file 'ABC.mat'
>A % the value of A
If you want to store the data into an ASCII dat-file (in the current directory), make the filename the same as the name of the data and type ' -ascii' at the end of the save statement.
-ascii
>save B.txt B -ascii
However, with the save/load commands into/from a dat-file, the value of only one variable having the lowercase name can be saved/loaded, a scalar or a vector/matrix. Besides, nonnumeric data cannot be handled by using a dat-file. If you save a string data into a dat-file, its ASCII code will be saved. If a dat-file is constructed to have a data matrix in other environments than MATLAB, every line (row) of the file must have the same number of columns. If you want to read the data from the dat-file in MATLAB, just type the (lowercase) filename ***.txt after ' load', which will also be recognized as the name of the data contained in the dat-file.
load
>load b.txt %read the value of variable b from the ascii file 'b.txt'
At the MATLAB prompt, you can type 'nm112' (the filename excluding the extension name part ".m") and <Enter> key to run the following M-file "nm112.m" consisting of several file input(save)/output(load) statements. Then you will see the effects of the individual statements from the running results appearing on the screen.
%nm112.m
clear
A=[1 2 3;4 5 6]
B=[3;-2;1];
C(2)=2; C(4)=4
disp('Press any key to see the input/output through Files')
save ABC A B C %save A,B & C as a MAT-file named 'ABC.mat'
clear('A','C') %remove the memory about A and C
load ABC A C %read MAT-file to recollect the memory about A and C
save B.txt B -ascii %save B as an ASCII-file file named 'b.txt'
clear B
load b.txt %read ASCII-file to recollect the memory about b
b
x=input('Enter x:')
format short e
x
format rat, x
format long, x
format short, x
The command 'input' enables the user to input some data via the keyboard. For example,
input
>x=input('Enter x: ')
Enter x: 1/3
x= 0.3333
Note that the fraction 1/3 is a nonterminating decimal number, but only four digits after the decimal point is displayed as the result of executing the above command. This is a choice of formatting in MATLAB. One may choose to display more decimal places by using the command ' format', which can make a fraction show up as a fraction, as a decimal number with more digits, or even in an exponential form of a normalized number times 10 to the power of some integer. For instance:
format
>format rat % as a rational number
>x
x= 1/3
>format long % as a decimal number with 14 digits
x= 0.33333333333333
>format long e % as a long exponential form
x= 3.333333333333333e-001
>format hex % as a hexadecimal form as represented/stored in memory
x= 3fd5555555555555
>format short e % as a short exponential form
x= 3.3333e-001
>format short % back to a short form(default)
Note that the number of displayed digits is not the actual number of significant digits of the value stored in computer memory. This point will be made clear in Section 1.2.1.
There are other ways of displaying the value of a variable and a string on the screen than typing the name of the...
Dateiformat: ePUBKopierschutz: Adobe-DRM (Digital Rights Management)
Systemvoraussetzungen:
Das Dateiformat ePUB ist sehr gut für Romane und Sachbücher geeignet – also für „fließenden” Text ohne komplexes Layout. Bei E-Readern oder Smartphones passt sich der Zeilen- und Seitenumbruch automatisch den kleinen Displays an. Mit Adobe-DRM wird hier ein „harter” Kopierschutz verwendet. Wenn die notwendigen Voraussetzungen nicht vorliegen, können Sie das E-Book leider nicht öffnen. Daher müssen Sie bereits vor dem Download Ihre Lese-Hardware vorbereiten.Bitte beachten Sie: Wir empfehlen Ihnen unbedingt nach Installation der Lese-Software diese mit Ihrer persönlichen Adobe-ID zu autorisieren!
Weitere Informationen finden Sie in unserer E-Book Hilfe.