Presentation is loading. Please wait.

Presentation is loading. Please wait.

Program design and algorithm development We will consider the design of your own toolbox to be included among the toolboxes already available with your.

Similar presentations


Presentation on theme: "Program design and algorithm development We will consider the design of your own toolbox to be included among the toolboxes already available with your."— Presentation transcript:

1 Program design and algorithm development We will consider the design of your own toolbox to be included among the toolboxes already available with your version of MATLAB e.g. SIMULINK, the Symbolic toolbox, and the Controls toolbox This is a big advantage of MATLAB (and tools like this software); it allows you to customize your working environment to meet your own needs. It is not only the ‘mathematics handbook’ of today’s student, engineer and scientist, it is also a useful environment to develop software tools that go beyond any handbook to help you to solve relatively complicated mathematical problems. Your ability to use the complete power of MATLAB is limited only by your experience and educational background. In the first part, we shall discuss the design process and later examine additional examples of the structure plan, which is the detailed description of the algorithm to be implemented

2 Computer program design process The designs of useful utilities translated into the MATLAB language (either sequences of command lines or functions, which are described later in the text) and saved as M-files in your work directory are the primary and most useful goals of users of tools like MATLAB. There are numerous toolbox in MATLAB but It will be helpful for you to search the MathWorks web site for the variety of products available to help the engineer, scientist and technical manager; it is located on the network at http://www.mathworks.com/. Conditions of computer program design For programs to work well they must satisfy the requirements associated with the problem or class of problems it is intended to solve. method of processing and condition Input

3 Design process outlines The steps as follows: 1 Problem analysis -The context of the proposed investigation must be established to provide the proper motivation for the design of a computer program. 2 Problem statement - Develop a detailed statement of the mathematical problem to be solved with a computer program. 3 Processing scheme - Define the inputs required and the outputs to be produced by the program. 4 Algorithm -Design the step-by-step procedure using the top-down design process that decomposes the overall problem into subordinate problems 5 Program algorithm - Translate or convert the algorithm into a computer language and debug the syntax errors until the tool executes 6 Evaluation -Test all of the options and conduct a validation study of the computer program (compare similar task) 7 Application - Solve the problems the program was designed to solve.

4 Example of a structure program (MATLAB) F = input(’Temperature in degrees F:’) C = (F-32)*5/9; disp([’Temperature in degrees C = ’,num2str(C)]) % STOP Note: Define your variable F 1. >> F= [212, 300, 350] F = 212 300 350 >> C = (F-32)*5/9; >> disp(['Temperature in degrees C = ',num2str(C)]) Temperature in degrees C = 100 148.8889 176.666

5 >> x = -1:0.001:1; % Compute the arc-functions: y1 = acos(x); y2 = asin(x); y3 = atan(x); % Convert the angles from radians to degrees: y1 = 180*y1/pi; y2 = 180*y2/pi; y3 = 180*y3/pi; %Plot the results: plot(y1,x,y2,x,y3,x),grid,legend(’asin(x)’, ’acos(x)’, ’atan(x)’) xlabel(’\theta in degrees’),ylabel(’x, the argument of the function’) % % REMARKS: Note the following: % (1) The acos(x) varies from 0 to 90 to 180 degrees. % (2) The asin(x) varies from -90 to 0 to 90 degrees. % (3) The atan(x) varies from -45 to 0 to 45 degrees. % % Stop Example 2

6 Graphical users interface design environments' - GUIDE Basic 2-D graphs Graphic (in 2-D) are drawn with the plot statement. In its simplest form, it takes a single vector argument. as in plot(y) e.g. plot(rand(1, 40)). Note: If y is a matrix, its columns are plotted against element indexes. Axes are automatically scaled and drawn to include the minimum and maximum data points The most common form of plot is plot(x, y) where x and y are vectors of the same length Example: x = 0:pi/40:4*pi; plot(x, sin(x))

7 Straight-line graphs are drawn by giving the x and y coordinates of the end-points in two vectors. Example To draw a line between the point with Cartesian coordinates (0, 1) and (4, 3) use the statement plot([0 4], [1 3]) MATLAB has a set of ‘easy-to-use’ plotting commands, all starting with the string ‘ez’. The easy-to-use form of plot is ezplot. Example ezplot(’sin(x)’)

8 Multiple plots on the same axes There are at least three ways of drawing multiple plots on the same set of axes (which may however be rescaled if the new data falls outside the range of the previous data). 1.The easiest way is simply to use hold to keep the current plot on the axes. All subsequent plots are added to the axes until hold is released, either with hold off, or just hold, which toggles the hold state. 2.The second way is to use plot with multiple arguments, e.g. plot(x1, y1, x2, y2, x3, y3,... ). Example: plot([0 4], [1 3], [2 5], [0 -2]) OR plotyy(x,sin(x), x, 10*cos(x)) 3.The third way is to use the form, example: plot(x, y)

9 Multiple plots in a figure: subplot One can show a number of plots in the same figure window with the subplot function. The statement subplot(m, n, p). subplot(2,2,1) mesh(z),title('subplot(2,2,1)') subplot(2,2,2) mesh(z) view(-37.5,70),title('subplot(2,2,2)') subplot(2,2,3) mesh(z) view(37.5,-10),title('subplot(2,2,3)') subplot(2,2,4) mesh(z) view(0,0),title('subplot(2,2,4)') x = 0:pi/40:2*pi; polar(x, sin(2*x)),grid Example 2

10 3-D plots The function plot3 is the 3-D version of plot. The command plot3 (x, y, z). The projection of a line in 3-D through the points whose coordinates are the elements of the vectors x, y and z. e.g. plot3(rand(1,10), rand(1,10), rand(1,10)) Example 1. Mesh surface [x y ] = meshgrid(-8 : 0.5 : 8); r = sqrt(x.^2 + y.^2) + eps; z = sin(r)./ r; [x y] = meshgrid(0:5); z = x.^2 - y.^2; >> mesh(z) 2. Mesh surface [x y ] = meshgrid(0 : 0.25 : 5); >> r = sqrt(x.^2 + y.^2) + eps; >> z = sin(r)./ r; >> [x y ] = meshgrid(0 : 5); >> mesh (z) 3. Contour plots [x y] = meshgrid(-2:.2:2); >> z = x.* exp(-x.^2 - y.^2); >> meshc(z) [x,y] = meshgrid (-2*pi:0.1:2*pi); z = cos(x).*sin(y); mesh(x,y,z),xlabel('x'),ylabel('y'),zlabel('z') 4. Multiple distributions


Download ppt "Program design and algorithm development We will consider the design of your own toolbox to be included among the toolboxes already available with your."

Similar presentations


Ads by Google