Question: Write a function in MATLAB named is_palindrome that satisfies the following function contract: % This function determines if an array is a palindrome. A palindromic

Write a function in MATLAB named "is_palindrome" that satisfies the following function contract:

% This function determines if an array is a palindrome. A palindromic % array is one where the values are the same if read from left-to-right % or from right-to-left. For instance, the following arrays are palindromes: % % [ 3 1 8 1 3 ] , [ 4 2 2 4 ], and ['n', 'o', 'o', 'n'] % % If the input array is a palindrome, true is returned in the output variable. % If the input array is not a palindrome, false is returned in the output variable. % % Parameters: % data -- any array containing one row of data. % % Returns: % result -- true if data is a palindrome, false otherwise 

Make sure your function is in a file named "is_palindrome.m". Thoroughly test it, then submit this file (and any supporting functions) below.

Hints: Your code will be similar to the 'reverse' function you wrote in lab. Also, to return true, you just need to store true in your output variable: result = true; Finally, if you write this correctly (and simply), your code will work on arrays of numbers or characters. (You don't need to do anything special for character arrays.)

Part 2: Write a script for testing part 1

Write a small script for testing part 1 of this assignment. Call your script "test_part_1.m". Your script should do the following:

Print a greeting and simple instructions for the user.

Prompt the user to input a single word.

Input a text string from the user.

Test the text string/array to see if it is a palindrome. Your script must call the function you wrote in part 1.

Print out a message to the user that indicates if their word is or is not a palindrome. Make the message user-friendly, such as: "Your word, noon, is a palindrome." (This exact form is not required.)

Test your script thoroughly, then submit the file (and any supporting functions) below.

Hints: Make sure to use the correct form of the input function call -- use the one that allows the user to input a string. Also, text strings are just arrays of characters. (You don't need to convert the text string to an array, it is already an array.)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!