Question
MATLAB. You are given a code (the correct one) as well as an incorrect version in which their task consists of converting dollars to yens,
MATLAB. You are given a code (the correct one) as well as an incorrect version in which their task consists of converting dollars to yens, yens to german marks then to dollars, and german marks to euros and then to dollars as well as making a conversion table for dollars = [0:1:100] to yens, german marks and euros (and you have to print your results in an external file in steps of 1 dollar from [0,10] and in steps of 10 dollar from [10,100]. The output of the correct code and the incorrect code will be shown. Please identify and comment what changes were done to the incorrect code that make the correct code run as specified.
--------------------------------------------------------------------------------------
Correct Code
clc, clear
FID=fopen('ConversionTable2.txt','w');
Y=@(D) D.*80; % converts Dollars to Yens G=@(D) Y(D)./62.42; % converts Dollars to Yens and then Yens to German Marks E=@(D) G(D)./1.95583; % converts Dollars to German Marks and then GM to Euros] D=[0:9 10:10:100]; % dollar vector
fprintf(FID,'%9s %9s %9s %9s ','Dollar', 'Yen', 'Mark','Euro');
for ii=1:numel(D)
fprintf(FID,'%9.2f %9.2f %9.2f %9.2f ',D(ii), Y(D(ii)),G(D(ii)), E(D(ii)));
end fclose(FID);
--------------------------------------------------------------------------------------
Incorrect Code
clc, clear
FID=fopen('ConversionTable2.txt','w'); Y=@(D) D.*80; % converts Dollars to Yens G=@(D) Y(D)./62.42; % converts Dollars to Yens and then Yens to German Marks E=@(D) G(D)./1.95583; % converts Dollars to German Marks and then GM to Euros D=[0,100]; % dollar vector fprintf(FID,'%9s %9s %9s %9s ','Dollar', 'Yen', 'Mark','Euro'); jj=20; % aux variable to jump 10 by 10
for ii=1:numel(D) if ii
end fclose(FID);
--------------------------------------------------------------------------------------
Correct Output
------------------------------------------------------------------------------------
Incorrect Output
incorrect code.nm correct_code.m Dollar 0.00 1.00 2.00 3.00 4.00 5.00 6.00 7.00 8.00 9.00 10.00 Yen 0.00 80.00 160.00 240.00 320.00 400.00 480.00 560.00 640.00 720.00 800.00 20.00 1600.00 30.00 2400.00 40.00 3200.00 50.00 4000.00 60.00 4800.00 70.00 5600.00 80.00 6400.00 90.00 7200.00 100.00 8000.00 Mark 0.00 1.28 2.56 3.84 5.13 6.41 7.69 8.97 10.25 11.53 12.82 25.63 38.45 51.27 64.08 76.90 89.71 102.53 115.35 128.16 ConversionTable2.txt Euro 0.00 0.66 1.31 1.97 2.62 3.28 3.93 4.59 5.24 5.90 6.55 13.11 19.66 26.21 32.76 39.32 45.87 52.42 58.98 65.53 1 2 3 4 6 7 10 12 13 14 15 16 17 18 19 20 21Step 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