tags: Matlab Workshop --- # Student code ## Lesson 8: Work with multiple functions ### Example Needleman-Wunsch Algorithm for Sequence Alignment 1. Name: ```matlab= ``` 2. Name: ```matlab= ``` ## Lesson 3: Loop ### Example 2: #### 1. Name: Xuan ```matlab= seq1 = ['A', 'C', 'G', 'T', 'A', 'C']; seq2 = ['A', 'C', 'G', 'A', 'A', 'T']; % For loop if length(seq1) ~= length(seq2) disp('Error: Sequences must be of the same length.'); else sum = 0; for i = 1:length(seq1) if seq1(i) ~= seq2(i) sum = sum + 1; end end fprintf('Number of mismatch: %d', sum); end % While loop if length(seq1) ~= length(seq2) disp('Error: Sequences must be of the same length.'); else sum = 0; i = 0; while i < length(seq1) i = i + 1; if seq1(i) ~= seq2(i) sum = sum + 1; end end fprintf('Number of mismatch: %d', sum); end ``` #### 2. Name: jia-hong Xu ```matlab= seq1 = ['A', 'C', 'G', 'T', 'A', 'C']; seq2 = ['A', 'C', 'G', 'A', 'A', 'T']; mismatch = 0; if length(seq1) ~= length(seq2) disp('Error: Sequences must be of the same length.'); else for i = 1:length(seq1) if seq1(i) ~= seq2(i) mismatch = mismatch + 1; end end disp(mismatch) end ``` #### 3. Name:D ```matlab= % Here is your code seq1 = ['A', 'C', 'G', 'T', 'A', 'C']; % ACGTAC seq2 = ['A', 'C', 'G', 'A', 'A', 'T']; % ACGAAT mis_sum =0; if length(seq1) ~= length(seq2) disp('Error: Sequences must be of the same length.'); else for i = 1:length(seq1) if seq1(i) ~=seq2(i) mis_sum = mis_sum +1; end end if mis_sum ~= 0 fprintf('Total number of mismatches: %d\n', mis_sum) else disp('total match') end end ``` #### 4. Name: ANJIE ```matlab= % Here is your code % Define nucleotide sequences using numbers seq1 = ['A', 'C', 'G', 'T', 'A', 'C']; % ACGTAC seq2 = ['A', 'C', 'G', 'A', 'A', 'T']; % ACGAAT % Check if the sequences are of the same length if length(seq1) ~= length(seq2) disp('Error: Sequences must be of the same length.'); else % Use for/while loop to count the mismatch count = 0; n = 1; while n < length(seq1) n = n + 1; if seq1(n) ~= seq2(n) count = count + 1; end end end ``` #### 5. Name:Jimmy ```matlab= seq1 = ['A', 'C', 'G', 'T', 'A', 'C']; % ACGTAC seq2 = ['A', 'C', 'G', 'A', 'A', 'T']; % ACGAAT % Check if the sequences are of the same length if length(seq1) ~= length(seq2) disp('Error: Sequences must be of the same length.'); else mismatch = 0; n = 0; for i = 1:length(seq1) n = n + 1; if seq1(n) ~= seq2(n); mismatch = mismatch + 1; end end end ``` #### 3. Name:Kuo ```matlab= % Here is your code % Define nucleotide sequences using numbers seq1 = ['A', 'C', 'G', 'T', 'A', 'C']; % ACGTAC seq2 = ['A', 'C', 'G', 'A', 'A', 'T']; % ACGAAT % Check if the sequences are of the same length if length(seq1) ~= length(seq2) disp('Error: Sequences must be of the same length.'); else n=6; matches=0; for i=1:n% if seq1(i)==seq2(i) matches=matches+1; else matches=matches+0; end end disp(matches); end ``` ## Lesson 4 Functions #### 1. Name:Jimmy ```matlab= function [alignment] = sequence_alingment(seq1, seq2) i = length(seq1) + 1; j = length(seq2) + 1; matrix_A = zeros(i, j); if length(seq1) ~= length(seq2) error('Sequences must be of equal length'); end for w = 1:length(seq1) for f = 1:length(seq2) if seq1(w) == seq2(f) matrix_A(f+1, w+1) = 1; end end end ``` ## Lesson 5 Recursion, Dynamic Programming ### Recursion Fibonacci sequence #### Name: Jimmy ```matlab function result = fibonacci(i) if i > 2 result = fibonacci(i-1) + fibonacci(i-2) else result = 1 end end ``` #### Name:YI-KANG ```matlab function result = fibonacci(i) if i > 0 && i <= 2 result = 1; else result = fibonacci(i-2) + fibonacci(i-1); end end ``` #### Nmae:jeff ``` function result = fibonacci(i) if i == 1 || i == 2 result = 1; % some equation you want to put else result = fibonacci(i-1) + fibonacci(i-2); % equation for getting the fibonacci sequence end end ``` function result = fibonacci(n) if n <= 2 result = 1; else result = fibonacci(n-2) + fibonacci(n-1); end end ## Lesson 6 Put your code here ...