matlab编程问题,希望大家能帮我解决,1.Write a simple MATLAB program,using an appropriate loop structure,that prints out the string “Hello World!” to the screen exactly 10 times.2.Write a MATLAB program which continues to ask the user f
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/24 20:46:18
matlab编程问题,希望大家能帮我解决,1.Write a simple MATLAB program,using an appropriate loop structure,that prints out the string “Hello World!” to the screen exactly 10 times.2.Write a MATLAB program which continues to ask the user f
matlab编程问题,希望大家能帮我解决,
1.Write a simple MATLAB program,using an appropriate loop structure,that prints out the string “Hello World!” to the screen exactly 10 times.
2.Write a MATLAB program which continues to ask the user for numerical input until the number ‘0’ is entered.Once this occurs,the total of all the numbers entered should be displayed.
3.Modify question (2) such that the product,mean,maximum value and minimum value of the numbers is also displayed.Note that in these cases the final ‘0’ should not be included in the calculation!
4.Modify question (3) so that instead of continuing until ‘0’ is entered,the program first prompts the user to enter how many numbers are to be entered,and then reads in exactly this many numbers (and performs the same calculations).
5.
a) Write a MATLAB program which prompts the user for two numbers,and then creates an array of values between these two numbers with 100 data points.Use the linspace command to do this.
b) Calculate the sine of this matrix,and plot the result using the plot command.Type “help plot” to get information on how this command works.
6.a) Write a program which prompts the user to enter a number,and then continuously divides that number by 2 and prints the remainder to the screen,stopping when the number reaches zero.For example,if the user enters 37,the program should print:
1 (37 / 2 = 18 rem 1)
0 (18 / 2 = 9 rem 0 )
1 (9 / 2 = 4 rem 1 )
0 ( 4 / 2 = 2 rem 0 )
0 ( 2 / 2 = 1 rem 0 )
1 ( 1 / 2 = 0 rem 1 )
b) You may have noticed that the operation above is that used to calculate the binary representation of a number,in reverse order.Modify your program so that the binary representation (in correct order) is printed to the screen instead,on a single line.Hint:
you will need store each remainder value into a matrix,then display each value of this matrix in reverse order once calculations are finished.Ensure that you keep careful track of which matrix index you are modifying each time using a counter variable.
matlab编程问题,希望大家能帮我解决,1.Write a simple MATLAB program,using an appropriate loop structure,that prints out the string “Hello World!” to the screen exactly 10 times.2.Write a MATLAB program which continues to ask the user f
1、
str='Hello World!';
for i=1:10
sprintf('第%d次:%s\n',i,str)
end
the result:
ans =
第1次:Hello World!
ans =
第2次:Hello World!
ans =
第3次:Hello World!
ans =
第4次:Hello World!
ans =
第5次:Hello World!
ans =
第6次:Hello World!
ans =
第7次:Hello World!
ans =
第8次:Hello World!
ans =
第9次:Hello World!
ans =
第10次:Hello World!
2、
clc;
clear;
i=1;
while 1
str=input('Please input a number\n\n','s');
array(i)=str2num(str);
array
if(array(i)==0)
break;
end
i=i+1;
end
array
3、
clc;
clear;
i=1;
product=1;
while 1
str=input('Please input a number\n\n','s');
array(i)=str2num(str);
if(array(i)==0)
break;
end
product=product*array(i);
i=i+1;
end
array=array(1:i-1)
product
meanvalue=mean(array)
maxvalue=max(array)
minvalue=min(array)
4、