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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started