clear all
for loop_index = 1:2
x = input('Input number to convert');
units = input('Input the units to convert from')
if units == mm
cm = x/10
m = x/1000
inch = x/25.4
km = x/1000000
end
if units == cm
mm = x*10
m = x/100
inch = x/2.54
km = x/100000
end
if units == m
mm = x*1000
cm = x*100
inch = x*39.37
km = x/1000
end
end

 採用された回答

Stephan
Stephan 2019 年 12 月 4 日

1 投票

clear all
for loop_index = 1:2
x = input('Input number to convert');
units = input('Input the units to convert from','s')
if units == 'mm'
cm = x/10
m = x/1000
inch = x/25.4
km = x/1000000
end
if units == 'cm'
mm = x*10
m = x/100
inch = x/2.54
km = x/100000
end
if units == 'm'
mm = x*1000
cm = x*100
inch = x*39.37
km = x/1000
end
end

5 件のコメント

Jordan Birley
Jordan Birley 2019 年 12 月 4 日
%But i want it to only display the selected units answers. how do i do more than on else statments for the same if
clear all
for loop_index = 1:2
x = input('Input number to convert');
units = input('Input the units to convert from','s')
if units == 'mm'
cm = x/10
m = x/1000
inch = x/25.4
km = x/1000000
else units == 'cm'
mm = x*10
m = x/100
inch = x/2.54
km = x/100000
else units == 'm'
mm = x*1000
cm = x*100
inch = x*39.37
km = x/1000
end
end
Stephan
Stephan 2019 年 12 月 4 日
clear all
for loop_index = 1:2
x = input('Input number to convert:\n');
units = string(input('Input the units to convert from:\n','s'))
if units == "mm"
cm = x/10
m = x/1000
inch = x/25.4
km = x/1000000
elseif units == "cm"
mm = x*10
m = x/100
inch = x/2.54
km = x/100000
elseif units == "m"
mm = x*1000
cm = x*100
inch = x*39.37
km = x/1000
else
disp('Please choose a correct unit to convert from.')
end
end
merina amon
merina amon 2020 年 8 月 20 日
may i get some help on my script too, especially the equation part i keep getting error
M1=53 ; %mass
M2=62.096; %mass
k=3096000; % stiffness
f= 1277;%exciting force
w1= 241.6921;
w2= 223.2897;
for i = 1: 101
w=0:50:100;
x1= (2-((w/w2).^2))*f ./ ( (3-((w/w1).^2))*(2-((w/w2).^2))-(4*(k.^2)) );
x2 = (4*k*f)./( (3-((w/w1).^2)) * (2-((w/w2).^2))-(4*k.^2));
end
merina amon
merina amon 2020 年 8 月 20 日
here is the full script
M1=53 ; %mass
M2=62.096; %mass
k=3096000; % stiffness
f= 1277;%exciting force
w1= 241.6921;
w2= 223.2897;
for i = 1: 101
w=0:50:100;
x1= (2-((w/w2).^2))*f ./ ( (3-((w/w1).^2))*(2-((w/w2).^2))-(4*(k.^2)) );
x2 = (4*k*f)./( (3-((w/w1).^2)) * (2-((w/w2).^2))-(4*k.^2));
end
subplot (211);
plot (w, x1);
xlabel ('w')
ylabel ('X_1');
axis([0 8 -5 5]);
grid on;
subplot (212);
plot (w, x2);
title('Frequency Response of a harmonically two degree of freedom system')
xlabel ('w');
ylabel ('X_2');
axis([0 8 -5 5]);
grid on
Steven Lord
Steven Lord 2020 年 8 月 20 日
merina amon, your question doesn't seem to be related to the original question. Please post it as a new question. When you do be sure to include the full and exact text of the error message you received.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

質問済み:

2019 年 12 月 4 日

コメント済み:

2020 年 8 月 20 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by