MEWORK Matlab6(1 x blackboard.com 3788596-dt-content-rid-271041401/courses/ENGR1
ID: 3606596 • Letter: M
Question
MEWORK Matlab6(1 x blackboard.com 3788596-dt-content-rid-271041401/courses/ENGR1 11. 173 1.M31/HOMEWORK. Matlab6%2 1. Write a function (ispalindrome.m) that takes a single input argument which is a string that does not contain spaces and returns a single output argument which is a logical value representing whether or not the input string is a palindrome. A palindrome is a string, such as a word or phrase, which is the same forwards as backwards. For example, the string "Madam, I'm Adam" is a palindrome when punctuation, whitespace, and capitalization are ignored: madamim adam madamimadam. Other examples ofpalindromes include: "taco cat", "radar", "a Toyota", "never odd or even", "a man a plan a canal panama When the input is a palindrome, the output should be the logical value true. When the input is not a palindrome, the output should be the logical value false You may assume that the input is a string and that it does not contain spaces or punctuation. Challenge: do not assume the input is a string or clean. Perform input validation and remove the spaces and punctuation yourself 2. Write a function (reverse_sentence.m) that takes a single input argument which is a string containing a sentence (a sequence of words) and returns a single output argument which is a string containing the words in the input string in reverse order. For example, on input 'the quick brown fox jumps over the lazy dog',the function should return 'dog lazy the over jumps fox brown quick the' Remember to think before you code. Have pencil and paper next to you and sketch your algorithm as pseudocode or flow diagram. 3. Wrte a script to make a proper plot for Ohm's Law,V = IR, for currents ranging from 2A to 20A in steps of 2 and resistance values R1 = 9 and R2 19 .Explanation / Answer
Answer 1:
Save the followiing code in file named ispalindrome.m
function T = ispalindrome(s)
i = 1;
j = length(s); %last index
T = true; %assume it is palindrome
%compare character from front with one in back till the index i < j
while (i < j)
if s(i) ~= s(j)
T = false;
break
end
i = i + 1;
j = j - 1;
end
end
=================
You can now use the function , for e.g.
ispalindrome("racecar")
ispalindrome("madam")
ispalindrome("hello")
Please post the other questions, 1 question per post.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.