clc
%Part A
%A2
%The input for the number of nodes
num_nodesstr = input('Enter the Number of Nodes: ','s');
num_nodes = str2num(num_nodesstr);
%To find any errors for the input
if num_nodes < 4 || rem(num_nodes,2) ~= 0
fprintf ("This bridge is either too short or has an odd number of node.\n")
elseif num_nodes > 10
fprintf ("You have passed maximum nodes.\n")
elseif isempty(num_nodes)==1
fprintf ("That is not a number/n")
%A3
%To create a coordinate system for each node
%First portion find the length of nodes in the x direction
else
if num_nodes == 6
x = 0.2;
elseif num_nodes == 8
x = 0.3;
elseif num_nodes == 10
x = 0.4;
end
XMeasure = (0:0.1:x);
nodes_xdis = repelem(XMeasure,2);
%find the y coordinates
nodes_ydis = zeros(1, num_nodes);
i = 0;
while i<=num_nodes
i = i+1;
if rem(i,2)== 0
nodes_ydis(i) = -0.1;
else
end
end
%Combines the two nodes coordinates of x and y
beam_init = [nodes_xdis' nodes_ydis'];
%A4
%Cantivever at 6 nodes
if num_nodes == 6
canti_connect = [1 1 2 2 3 3 4 4 5];
canti_connectors = [2 3 3 4 4 5 5 6 6];
C = digraph(canti_connect,canti_connectors);
C1 = adjacency (C);
connect_mat_C = full(C1);
%Fixed at 6 nodes
fix_connect = [1 1 2 2 3 3 4 4 5];
fix_connectors = [2 3 3 4 4 5 5 6 6];
F = digraph(fix_connect,fix_connectors);
F1 = adjacency (F);
connect_mat_F = full(F1);
shape = 9;
%Cantiverer at 8 Nodes
elseif num_nodes == 8
canti_connect = [1 1 2 2 3 3 4 4 5 5 6 6 7 8];
canti_connectors = [2 3 3 4 4 5 5 6 6 7 7 8 8 9];
C = digraph(canti_connect,canti_connectors);
C1 = adjacency (C);
connect_mat_C = full(C1);
%Fixed at 8 nodes
fix_connect = [1 1 2 2 3 3 4 4 5 5 6 6 7];
fix_connectors = [2 3 3 4 4 5 5 6 6 7 7 8 8];
F = digraph(fix_connect,fix_connectors);
F1 = adjacency (F);
connect_mat_F = full(F1);
shape = 13;
%Cantiverer at 10 Nodes
elseif num_nodes == 10
canti_connect = [1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9];
canti_connectors = [2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10];
C = digraph(canti_connect,canti_connectors);
C1 = adjacency (C);
connect_mat_C = full(C1);
%Fixed at 10 Nodes
fix_connect = [1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9];
fix_connectors = [2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10];
F = digraph(fix_connect,fix_connectors);
F1 = adjacency (F);
connect_mat_F = full(F1);
shape = 17;
end
%A5
b_type = input("0 for Cantilever\n1 for Fixed\nChoose Analysis: ",'s');
b_type1 = str2num(b_type);
if b_type1 == 0
connect_mat = connect_mat_C;
imagesc(connect_mat)
title("Connectivity Matirx")
axis off
elseif b_type1 == 1
connect_mat = connect_mat_F;
imagesc(connect_mat)
title("Connectivity Matirx")
axis off
elseif b_type ~= 0 || b_type~=1
fprintf("Error when selecting\n")
end
%A6
%convert all to connections 0.1meters length
connect_mat_length = connect_mat;
connect_mat_length(connect_mat_length==1) = 0.1;
%Understanding pattern of the diagonal connection(2,3) (4,5) etc, we can
%then find and add in the diagonal connections length
xspace = linspace(2,num_nodes,num_nodes/2);
xspace(end) = [];
xspace = xspace';
yspace = linspace(3,num_nodes-1,num_nodes/2.5);
yspace = yspace';
i = 1;
while i<=length(xspace)
connect_mat_length(xspace(i),yspace(i)) = 0.1*sqrt(2);
i= i+1;
end
end
%A7
%Finding the index coordinates of the connected nodes
[row, col] = find(connect_mat_length~=0);
A7 = [row col];
%A8
updated_seg_length = @(p1,p2,q1,q2) sqrt((p1-q1).^2+(p2-q2).^2);
clear Nodes_dis
r = 1;
while r<=num_nodes
Nodes_dis(:,r) = updated_seg_length(beam_init(r,1),beam_init(r,2),beam_init(:,1),beam_init(:,2));
r = r+1;
end
b = delaunay(beam_init(:,1),beam_init(:,2))
a = triplot(b, A7(:,1),A7(:,2));