Beruflich Dokumente
Kultur Dokumente
Worksheet 3A
1. Write a simple script that will calculate the volume of a hollow sphere which is
4 3
(ro ri3 ) where ri is the inner radius and ro is the outer radius. Assign a value to a
3
variable for the inner radius, and also assign a value to another variable for the outer
radius. Then, using these variables, assign the volume to a third variable. Include
comments in the script.
1. % Assgign values respectively for the inner raidus ri and
2. % the outer radius ro
3. ri = input('Enter the value of the inner radius in meters: ');
4. ro = input('Enter the value of the outer raidus in meters: ');
5. %Calculate volume of the hollow sphere
6. V= 4*pi/3*(ro^3ri^3);
7. fprintf('The volume of the hoolow sphere is %f,\n',V)
mat =
91 96 64 99
96 82 77 58
56 54 98 99
3. In the Command Window, create x and y data points by creating x and y vectors,
Use the bar function instead of plot to get a bar chart.
>> ylabel('Temperature')
>> x=1:12;
>> y=randi([10,100],1,12);
>> bar(x,y)
>> xlabel('Month')
>> ylabel('Temperature')
4. Experiment, in the Command Window, with the fprintf function. Make a note of
what happens for each.
First, use fprintf to print the real number 12345.6789
without specifying any field width
in a field width of 10 with 4 decimal places
in a field width of 10 with 2 decimal places
in a field width of 6 with 4 decimal places
in a field width of 2 with 4 decimal places
7. Write a script to prompt the user for the length and width of a rectangle, and print its
area with 2 decimal places. Put comments in your script.