SUNY Geneseo Department of Mathematics
Wednesday, September 23
Math 230 01
Fall 2015
Prof. Doug Baldwin
abs
gives absolute value of all numbers in vector>> v1 = [ 1 2 3 4 ];
>> v2 = [ 20 30 40 10 ];
>> sum = v1 + v2
sum =
21 32 43 14
>> sum / 2
ans =
10.5000 16.0000 21.5000 7.0000
>> sum ./ 2
ans =
10.5000 16.0000 21.5000 7.0000
>> products = v1 * v2
{Error using *
Inner matrix dimensions must agree.}
>> products = v1 .* v2
products =
20 60 120 40
>> sqrt( products )
ans =
4.4721 7.7460 10.9545 6.3246
>> products ^ 0.5
{Error using ^
Inputs must be a scalar and a square matrix.
To compute elementwise POWER, use POWER (.^) instead.}
>> products .^ 0.5
ans =
4.4721 7.7460 10.9545 6.3246
>> nthroot( products, 2 )
ans =
4.4721 7.7460 10.9545 6.3246
>> numbers = [ 3.6 9.1 5.34 ]
numbers =
3.6000 9.1000 5.3400
>> round( numbers )
ans =
4 9 5
volumeCylinder
function from
Sept. 18 to work on vectors>> volumeCylinder( [1 2], [2 0.5] )
{Error using ^
Inputs must be a scalar and a square matrix.
To compute elementwise POWER, use POWER (.^) instead.
Error in volumeCylinder line 4
volume = pi * radius^2 * height; }
% Change “volumeCylinder.m” file as follows:
function [ volume ] = volumeCylinder( radius, height )
%VOLUMECYLINDER Compute volume of one or more cylinders from radii and
%heights
volume = pi * radius.^2 .* height;
end
>> volumeCylinder( [1 2], [2 0.5] )
ans =
6.2832 6.2832
>> sin( pi/2 )
ans =
1
>> sind( 90 )
ans =
1