Professional Documents
Culture Documents
Sol
Algorithm
1. Make a user based script.
2. Display what script will calculate
3. Display units
4. Put a caution of not entering a vector or a matrix
5. Get the inputs from the user of outer radius and inner radius.
6. Calculate the Volume by the formula given
7. Include the comments in the script .
M file
volume=(4*3.14)/3*((radiusouter)^3-(radiusinner)^3);
fprintf('The volume of a hollow sphere is = %3.2f\n',volume);
Output
Sol
Algorithm
1. Display what script will calculate.
2. Inputs are given .
3. Put the inputs in the formula
4. Display the output
M file
disp('This software will calculate the molecular weigth of hydrogenperoxide');
oxygen=15.9994;
hydrogen=1.0079;
h2o2=(hydrogen*2)+(oxygen*2);
Output
Sol
Algorithm
M file
string=length(mystring);
output
This software will show the length of the string
Algorithm
1. Display script use.
2. Get the input of a real number
3. Show the output upto two decimal places
M file
disp('This software will show the real number upto 2 decimal places');
Output
This software will show the real number upto 2 decimal places
Algorithm
1. Take the input of a matrix or variable from the user.
2. Show the output using fprintf command.
3. Experiment with different examples.
M file
matrixvector=input('Enter a marix or a vector=');
output
Enter a marix or a vector=[1 2 3]
123>>
147258369>>
142536>>
Sol
Command window
>> value=12345.6789
value =
1.2346e+004
a)
b)
c)
d)
e)
Command window
a)
b)
c)
d)
Command window
>> x=12.34
x=
12.3400
>> y=4.56
y=
4.5600
a)
x is 12.340
b)
c)
Sol
Algorithm
1. Display the use of script.
2. Display the units.
3. Get the input from the user of length and width
4. .The area of the rectangle.
M File
length=input('Enter a length=');
width=input('Enter a width=');
area=length*width;
Output
Enter a length=4
Enter a width=7
Sol
Algorithm
1. Display script use.
2. User enter his or her name.
3. That name will be shown in a sentence format given.
M file
disp('This software will get your name and show in a sentence format given.');
Output
This software will get your name and show in a sentence format given.
Sol
Algorithm
1. Display script use.
2. Get the input of string from user .
3. Display the string
M file
disp('This software will type the string in quotes');
Output
Sol
Algorithm
1. Display the use of script.
2. Take the input from user in degrees.
3. Make the logic.
4. Display the output in radians
Mfile
disp('This software converts angle from degrees to radians');
degrees=input('Enter the angle in degrees=');
radians=(degrees/pi);
Output
This software converts angle from degrees to radians
Sol
Algorithm
1. Display script use.
2. Enter yearly spending and monthly spending.
3. Make the logic.
4. Display the output.
Mfile
x=w/100;
y=x*yearlyspending;
z=x*monthlyspending; %logic
fprintf('%d %d %d \n',y);
fprintf('%d %d %d \n',z)
Output
This software shows the range of money spending on food
Sol
Algorithm
1. Display script use.
2. Take input from the user.
3. Make the logic.
4. Display the output.
5. Show the units.
M file
wingso=(weight/wingarea);
Output
Sol
Algorithm
1. Display Script use.
2. User don,t enters matrix or a vector.
3. User enters a x and y coordinate.
4. Plot that point on graph.
5. Use green + marking.
M file
disp('This software plots a point on graph');
plot(x,y,'g+')
Output
Sol
Algorithm
1. Display script use.
2. Get x values using colon operator.
3. Plot exp(x).
M file
disp('This script will plot exponential function')
x=-2:0.1:2;
y=exp(x);
plot(x,y,'r*')
xlabel('X')
ylabel('Y')
title('exponential graph')
output
Sol
Algorithm
M file
disp('This script will plot bar chart');
x=1:5:100;
y=sqrt(x);
bar(x,y)
Output
Sol
Algorithm
vec=randint(1,3,[1 ,100]);
x=1:length(vec);
plot(x,vec,'r*')
xlabel('X');
ylabel('Y');
title('graph')
Output
Sol
Algorithm
1. Display script use.
2. Plot 0-10 range.
3. Then Plot 0-100 range.
M file 1
x=linspace(0,pi,10);
y=sin(x);
plot(x,y)
Output1
MFile2
disp('This script plots sinx 0-100 range graph');
x=linspace(0,pi,100);
y=sin(x);
plot(x,y)
OUTPUT2
Sol
Sol
Sol
Sol
Sol
Algorithm
M file
width=input('Enter width=');
length=input('Enter length=');
area=(length*width);
Output
This software calculates the area of rectangle
Enter width=12
Enter length=21
The area is 252.000000
Sol
Algorithm
1. Display software use.
2. User enters in Fahrenheit.
3. Make the logic
4. Display the output.
M file
disp('This software will convert from fahrenheit to celsius and kelvin');
F=input('Enter value in fahrenheit=');
C=(F-32)*5/9;
K=C+273.15;
Output
Sol
Algorithm
Mfile
mps=(mph*3048)/(3600) ;
Output
Sol
Algorithm
M file
BMI=703*((weight)/(height^2));
OUTPUT
This software calculates BMI
Sol
Algorithm
1. Display software use
2. User enters total and static pressure
3. Put values in the formula
4. Show velocity
Mfile
velocity=1.016*(sqrt(tp-stp));
output
Sol
Algorithm
1. Display script use.
2. User enters the age.
3. Put age in the formula given.
4. Display THR which is output.
M File
disp('This software calculates the target heart beat ');
thr=(220-age)*.6;
Output
Sol
Algorithm
1. Display software use
2. User enters n value
3. Make logic
4. Display the output.
M File
disp('This software calculates the factorial using stirling formula');
a=sqrt(2*pi)*n*[n/exp(n)]^n; %Logic
Output
Sol
Algorithm
Mfile
disp('This script converts rain to snow in inches');
snow=rain*6.5;
Output
Algorithm
1. Display the use of script.
2. Enter a vector.
3. Make the logic.
4. Show the output.
M File
disp('This script generates the random element from the vector');
vec=input('Enter a vector=');
a=rand(1,1,[1,length(vec)]);
output
This script generates the random element from the vector
Enter a vector=[9 21 0]
Sol
Algorithm
1. Display script use.
2. User enters one value.
3. Make the logic .
4. Display the output.
Mfile
vecout=arg:1:(arg+5);
fprintf('%d %d %d %d %d %d',vecout);
output
In this script,From one arguement a vector will come in inrement of five
Enter a single integer arguement=4
4 5 6 7 8 9>>
Sol
Algorithm
1. Display software use
2. User enters two sides and the included angle
3. Make logic
4. Display the output
M file
a=b^2+c^2-(2*b*c)*(cosd(alpha));
side=sqrt(a);