Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Laboratory work 5.1eng.doc
Скачиваний:
0
Добавлен:
01.07.2025
Размер:
3.47 Mб
Скачать

Memberwise operations with vectors

To execute a memberwise increase, division, involution vectors, use the next signs of ".*", "./" ".^" (without blanks!). A vector ensues also.

Task 9.

 Set two vector-rows v1=[2 -3 4 1]; v2=[7 5 -6 9];

 You will execute a memberwise increase and division of these vectors.

 You will execute memberwise involution 2 for vector v1.

Increase, dividing of vector by a number is done by means of ordinary signs "*" "/" without a point.

Task 10.

 Set a row-vector with the co-ordinates of points 0.2, 0.3, 0.5, 0.8, 1.3, 1.7, 2.5

 Calculate function  from each element of a vector х.

It is often required to show out the value of function in points a segment, defending from each other on equal distance (step). For input of such vectors ":" is used. For example, it is required to enter a row-vector of argument values with a step 0.2.

In MatLab it will be written down so

>> x=[1:0.2:2]

x =

1.0000 1.2000 1.4000 1.6000 1.8000 2.0000

It is conditional it is possible to write down

x = [initial value: a step: final value].

A step can be both positive and negative.

Task 11.

Show out the table of values of function on a segment [0, 1] with a step 0.05.

Construction of charts of functions of one variable

For displaying of function it is necessary as a chart

1. To set the vector of values x.

2. To calculate the vector of values y of function y(x).

3. In a command line to set the command of plot for the construction of chart.

Task 12.

Build the chart of function, certain in a task 11. For this purpose enter in the command line

>> plot(x, y).

After instruction execution the window of Figure No 1 with the chart of function, represented on a picture on the left will appear on the screen. The command plot connects points with co-ordinates (x(i), y(i)) by straight lines, automatically scaling axes for the optimal location of chart in a window. The built chart must not have fractures, because function smooth. For more exact presentation of function it is needed to set the greater amount of points on a segment [0,1].

Task 13.

Through the keys ↑ ↓ find the before entered command of task of vector х, set more shallow step (0.01), find and will execute the command of calculation of function and again will start the construction of chart. The smooth chart of functions must turn out for you, as on a picture, located on the right.

Comparison of a few functions comfortably to make, displaying their charts on one axes.

Task 14.

Build on a segment [- 1, - 0.3] charts of functions and , using the command plot(x, f, x, g). A chart, shown on a picture on the left, must turn out.

The command plot allows to set style and color of lines, for example

plot(x,f,'k-',x,g,'k:') builds the first chart a continuous black line, and second dotted black line (picture on the right). Styles are set as a three character, put in single brackets set. The order of the following of symbols is unimportant.

Table of styles of task of color of chart, type of point-marker, type of marker

Color

Type of point

Line style

b dark blue

. . point

- continuous

g green

o group

: dotted

r red

x cross

-. штрих-пунктирная

c blue

+ plus

-- stroke

m violet

* asterisk

 

y yellow

s square

 

k black

d rhombus

 

 

If it is simultaneously needed to visualize a few charts in different windows, it is enough to execute commands

>> w=exp(x)

>>figure;plot(x, w)

Command figure will create a new graphic window.

Other decision of show of a few charts collision-free ranges of axes the use of function subplot is. For example, after implementation of next commands

>> x=[0:0.01:2];

>> y=sin(x);z=cos(x);w=exp(x);

>> subplot(1,2,1); plot(x, y, x, z)

>> subplot(1,2,2);plot(x, w)

a window with charts will look like the following:

The function subplot has three arguments: the first is equal to the number of rows of subregion, second - to the number of columns of subregion, and the third sets the number of subregion.

A construction of charts is in polar co-ordinates

To build a chart in polar co-ordinates, it is necessary to use the command polar. For example, for the construction of chart of function r= sin(3φ) in polar co-ordinates it is necessary to execute the group of commands

>> phi=0:0.01:2*pi; r=sin(3*phi);

>> polar(phi, r)

Task 15.

To build the chart of function for in the rectangular and polar system of co-ordinates in one window.

Characteristics of charts and graphic windows

Characteristics of lines. Function plot through supporting (calculated) points with the co-ordinates x, y conducts the segments of straight lines, which in the system are graphic objects of type of line. These objects are many characteristics and descriptions which can be changed. The delineator of graphic object returns the function plot and he can be memorized, for example, in the variable hPlot, and then by means of command get to look over.

>> hplot=plot(t,y);

>> get (hplot)

Color = [0 0 1]

EraseMode = normal

LineStyle = -

LineWidth = [0.5]

Marker = none

MarkerSize = [6]

MarkerEdgeColor = auto

MarkerFaceColor = none

XData = [ (1 by 401) double array]

YData = [ (1 by 401) double array]

ZData = []

BeingDeleted = off

ButtonDownFcn =

Children = []

Clipping = on

CreateFcn =

DeleteFcn =

BusyAction = queue

HandleVisibility = on

HitTest = on

Interruptible = on

Parent = [101.004]

Selected = off

SelectionHighlight = on

Tag =

Type = line

UIContextMenu = []

UserData = []

Visible = on

Knowing the property name, by means of function set its value can be changed. For example, setting the command >> set(hplot,'linewidth',7), it is possible to change the thickness of line.

Task 16.

Build the chart of function y=sin(x), x  [0,3], step 0.1.

Characteristics of co-ordinates axes. In order to get the detailed image on more narrow area of chart, it is necessary to use a function

>> axis([1.5,2.5,0.5,2])

To change an amount and values of numerical marks on axes, it is necessary in the beginning to get description of object, which contains the co-ordinates axes and white rectangle which a chart is built into. It does function gca.

>> haxes=gca;

Then by means of function set to change the required parameters:

>> set(haxes', xtick ',[1.5,1.75,2.0,2.25,2.5])

Causing of measuring net

>> grid on

Filling in of general header of chart

>> title('Chart of function of sin(x)')

Task of headers of axes

>> xlabel('x');ylabel('y');

Placing of inscription on graphic arts locally

>> text(2.1,0.9',\leftarrowsin(x)');

Task 16.

Using, commands given above, obtain, that built in a task 15 a chart looked as on a picture on the right.

Charts of self-reactance and piece-set functions

At the construction of functions set it is self-reactance needed:

  1. to generate the vector of values of argument;

  2. to calculate the values of functions and write down them in vectors;

  3. to use the got vectors as arguments of function plot.

For example, chart of function turns out through next commands:

>> t=[0:0.01:2*pi];

>> x=0.5*sin(t);

>> y=0.7*cos(t);

>> plot(x, y)

At the construction of the piece-set functions it is necessary:

  1. to get the pair of arrays x, y for each of branches;

  2. to unite the values of abscissas in the vector x;

  3. to unite the values of ordinates in the vector y;

  4. to build the chart of function, by the set pair of arrays of x and y.

For example, chart of function

turns out through next commands:

>> x1=[-2*pi :0.01:- pi];

>> y1=pi*sin(x1);

>> x2=[-pi :0.01: pi];

>> y2=pi - abs(x2);

>> x3=[pi :0.01:2*pi];

>> y3=-pi*sin(x3) .^3;

>> x=[x1 x2 x3];

>> y=[y1 y2 y3];

>> plot(x, y)

It is possible to build the chart of three branches, as three different functions

>> plot (x1, y1, x2, y2, x3, y3), then every part is built by the color

Task 17.

Build the chart of function

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]