For each of the problems in this lab assignment, write a separate MATLAB m-file.
ID: 3811561 • Letter: F
Question
For each of the problems in this lab assignment, write a separate MATLAB m-file. The name of each m-file must be exactly as specified in the corresponding problem statement. Submit your m files by uploading to Blackboard before the due date. A p-file (an encrypted script file) for problem 2 is available on the Lab page of the course website. You can download this file and run it from the command line to see how your code should behave. Make the behavior of your code match that of the p-file. 1. Filename: MAE1090_Lab 7_1 middot m Write an m-file to add two 30-digit numbers and print the results. This is not as easy as it might sound at first because integer types may not be able to store a value this large. One way to handle large integers is to store them in vectors, where each element in the vector stores a digit of the integer. Your script should initialize two 30-digit integers, storing each in a vector, and then add these integers, also storing the result in a vector. Create the original numbers using the built in function randi middot m. 2. Filename: MAE1090_Lab 7_1 middot m Amino acids are the fundamental compounds that make up proteins. Viruses, such as influenza and HIV, have genomes which code for proteins that have pathogenic results. Human bodies recognize foreign proteins by binding them to other molecules so that they can be recognized and killed. Write an m-file. That determines whether an amino acid is going to bind to a certain molecule. It is known that the first region (1 - 5) of the molecule bonds strongly to amino acids A, C, I, L, Y, and E, and weakly to W, S, M, G, and K. It is also know that the second region (6 - 10) binds strongly to H, D, W, K, L, and A, and weakly to I, E, P, C, and T. Your m-file should prompt the user for two things: the region number and a character for the amino acid. The script should then determine whether the amino acid and the molecule results in a "strong" or "weak" binding.Explanation / Answer
///////////// program 1
% MAE1090_Lab7_1.m
% Logic behind this code is = accept 2 numbers as string
% reverse the strings, convert strings to vector, find the length of smaller vector
% do the addition of number in vector one by one, use c variable as carry.
% copy the remaining number from larger vector v to result vector v3
% convert vector v3 to string, reverse the string and display the result.
clear
str1 = input('Enter first number :','s');
% 's' indicates that name is a string.
str2 = input('Enter second number :','s');
% reverse input strings
fliplr(str1)
fliplr(str2)
% convert str1 and str2 to v1 and v2
v1 = str1 - ‘0’
v2 = str2 - ‘0’
len1 = length(v1);
len2 = length(v2);
if len1 > len2
len = len2;
else
len = len1;
end
% v3 stores the added number (result)
v3 = [];
c = 0;
for i=1:len
v3(i) = v1(i) + v1(i);
v3(i) = mod(v3(i), 10) + c;
c = v3(i)/10;
end
if len1 > len2
len3 = len1 - len2
v = v1;
else
if len2 > len1
len3 = len2 - len1
v = v2;
else
if len1 == len2
len3 = 0;
end
end
end
if len3 == 0
if c != 0
v3(i) = v3(i) + c;
end
v3 = num2str(v3);
fliplr(v3)
disp(v3);
end
for i=len+1:len+l
v3(i) = mod(v(i) + c, 10)
c = v3(i)/10;
end
v3 = num2str(v3);
fliplr(v3)
disp(v3)
========================================================================
////////// Program 2
% Logic behind this code is =
% accept region number and name of amino acid as string
% if reg is not between 1 to 10, then display error and return.
% use switch case inside if to determine strong or weak.
% display the result and return
clear
reg = input(‘Enter region number:’);
name = input(‘Enter amino acid name:’,’s’);
name = upper(name);
if reg < 1
disp(‘Incorrect region number.’)
return;
else
if reg > 10
disp(‘Incorrect region number.’)
return;
end
end
if reg > 5
switch(name)
case ‘H’
disp(‘strong’)
case ‘D’
disp(‘strong’)
case ‘W’
disp(‘strong’)
case ‘K’
disp(‘strong’)
case ‘L’
disp(‘strong’)
case ‘A’
disp(‘strong’)
case ‘I’
disp(‘weak’)
case ‘E’
disp(‘weak’)
case ‘P’
disp(‘weak’)
case ‘C’
disp(‘weak’)
case ‘T’
disp(‘weak’)
otherwise
disp(‘Invalid combination’)
end
else
switch(name)
case ‘A’
disp(‘strong’)
case ‘C’
disp(‘strong’)
case ‘I’
disp(‘strong’)
case ‘L’
disp(‘strong’)
case ‘Y’
disp(‘strong’)
case ‘E’
disp(‘strong’)
case ‘W’
disp(‘weak’)
case ‘S’
disp(‘weak’)
case ‘M’
disp(‘weak’)
case ‘G’
disp(‘weak’)
case ‘K’
disp(‘weak’)
otherwise
disp(‘Invalid combination’)
end
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.