作业帮 > 综合 > 作业

matlab编程问题,实在是不会,希望大家能帮我解决,

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/16 01:55:22
matlab编程问题,实在是不会,希望大家能帮我解决,
Write a program which determines the resistance of two resistors connected either in series or parallel.The program should prompt the user for the values of each resistor,and then ask whether they are connected in series (‘s’) or parallel (‘p’).The formula for total resistance is:
Rseries = R1 + R2
Rpar = (R1*R2)/(R1+R2)
我英语不太好,理解上面的意思是,先输入两个电阻值,然后选择串并联,计算结果.
水平有限,不知是否符合你的要求,怀着助人为乐的心来的.
程序如下:
R1=input('请输入R1:');
R2=input('请输入R2:');
connect=input('请输入连接方式(s/p):','s');
switch connect
case 's'
R=R1+R2;
fprintf('串联电阻值为:%f\n',R);
case 'p'
R=R1*R2/(R1+R2);
fprintf('并联电阻值为:%f\n',R);
end