Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Issues with else / If command?

1 回表示 (過去 30 日間)
Johnny Boy
Johnny Boy 2014 年 12 月 9 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
The program is user-defined. So far I have:
Line 1: Rtotal=input('How many resistors are there? ');
Line 2: R1=input('What is R1? ');
Line 3: R2=input('What is R2? ');
Line 4: result = input('Are the resistors series or parallel?');
Line 5: if Series
Line 6: Series=(1./(R1 + R2)).^-1;
Line 7: end;
Line 8: if Parallel
Line 9: Parallel=R1+R2;
Line 10: end;
As seen below, the road bump occurs on line 4. The error I get when I type Series is:
Error using input
Undefined function or variable 'Series'.
Error in simple (line 4)
result = input('Are the resistors series or parallel?');
Why is this incorrect? Please assist.

回答 (1 件)

Star Strider
Star Strider 2014 年 12 月 9 日
編集済み: Star Strider 2014 年 12 月 9 日
I apologise for being direct, but you have multiple errors.
First, you need to test ‘result’ to see if it contains the string 'series' or 'parallel'.
Second, your formulae for the total resistance of series or parallel is reversed.
See if this works:
result = 'series'; % Create Data
if strcmpi(result,'series')
RT = R1+R2;
elseif strcmpi(result,'parallel')
RT = R1*R2/(R1+R2);
end
where ‘RT’ is the total resistance of the network.

この質問は閉じられています。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by