Question: Can anyone help with this MATLAB problem??? Thank you so much!! Write a function called rom2num that converts Roman numerals to numbers. Recall characters in

Can anyone help with this MATLAB problem??? Thank you so much!!

Write a function called rom2num that converts Roman numerals to numbers. Recall characters in Roman numerals are

numeral

number

I

1

V

5

X

10

L

50

C

100

D

500

M

1000

The input is a valid Roman numeral entered as a string. The output is a number. For example, rom2num(VII) yields 7.

There are many approaches. See section 9.2 of van Loan for an approach. We will discuss section 9.2 in lecture 5. A simpler approach is the following.

Write a function called Converter that takes the strings I,V,X,L,C,D,M and returns the corresponding numbers. Use the switch case construction for the different possibilities.

Set S=0.

Read the characters from left to right

At each step call the function Converter. Add the corresponding value to S.

At each step check the value of the previous character. If it is less, then subtract two times that value from S.

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!