BEST代写-线上编程学术专家

Best代写-最专业靠谱代写IT | CS | 留学生作业 | 编程代写Java | Python |C/C++ | PHP | Matlab | Assignment Project Homework代写

Matlab代写 | Maths 162 Semester 2, 2020 Assignment 6: Graphs and Markov Chains

Matlab代写 | Maths 162 Semester 2, 2020 Assignment 6: Graphs and Markov Chains

这个作业是用Matlab完成图相关的数学计算

Maths 162 Semester 2, 2020
Assignment 6: Graphs and Markov Chains

Problems
1. Let G be a graph. If you use G.Edges, MATLAB will give you a list of all of the edges in G:
>> G = randgraph(3,0.5);
>> G.Edges
ans =
2×1 table
EndNodes
1 3
2 3
Tables are surprisingly annoying to work with, however. Consider the following code, which
you would think is a reasonable way to ask for the first edge in G.Edges:
>> G.Edges(1)
Error using graph/subsref (line 27)
Subscripting into a table using one subscript (as in t(i)) or three or more
subscripts (as in t(i,j,k)) is not supported. Always specify a row subscript and a
variable subscript, as in t(rows,vars).
A good fix for this is to convert things into an array, which we’re more used to working with:
>> arrayofedges = table2array(G.Edges)
arrayofedges =
1 3
2 3
>> arrayofedges(1,1)
ans = 1
>> arrayofedges(1,2)
ans = 3
With this in mind, create a MATLAB function validcolour(G) that takes in as input a
graph G that has a property G.Nodes.Colour defined. It should go through all of the edges
of G, and for each edge {x, y} check whether the two endpoints of that edge have the same
colours or not (i.e. whether G.Nodes.Colour(x) == G.Nodes.Colour(y)).
If all of the edges have differently-coloured endpoints, then validcolour(G) should return 1;
otherwise, it should return 0.
2. In MATLAB, you can make your programs deliberately produce errors with the error(msg)
command. When you run this command, the string given by msg will appear in red, you’ll hear
the classic error “boing” sound effect, and MATLAB will stop trying to execute any future
lines of code.
1
>> error(‘behold, a custom error message’)
behold, a custom error message
>> error(‘behold, a custom error message with variables in: %d’, 23)
behold, a custom error message with variables in: 23
This can be useful if you want to ensure that someone can only use your function if they’ve
given it a reasonable input. You’re going to do this here!
Specifically, you’re going to create a MATLAB function called markov(A,i,j,s). It takes
in as inputs a matrix A that is supposed to be a n × n transition matrix for some Markov
chain, as well as values i and j that are supposed to be states in this Markov chain (i.e. values
1 . . . n.)

bestdaixie

评论已关闭。