# CIVE121 Study Guide - Interpolation, Printf Format String, Numerical Integration

22 views1 pages
Published on 17 Apr 2013
School
University of Waterloo
Department
Civil Engineering
Course
CIVE121
1 of 1
Vector Functions
total = sum(vec) avg = mean(vec)
num = length(vec) [value_max, index] = max(vec)
array = randi([1, 6], 5, 2) array = rand(5, 2)
[sorted_vec, order] = sort(vector, 'ascend' or 'descend')
Find and Logical
index = find(logical expression)
index = findstr(target_string, search_string)
Character Arrays
string = num2str(numeric value)
numeric value = str2num(character vector)
Cell Arrays
cell = {elements}
element = cell{index}
string = char(cell{index})
File IO
[col1, col2, etc.] = textread(filename, '%s%f etc.')
fid = fopen(filename)
cell_array = textscan(fid, '%s%f%f')
fclose(fid)
Numerical Integration and Differentiation
I = trapz(x_vector, y_vector)
der_coeff = polyder(coeff)
int_coeff = polyint(coeff)
Interpolation
y_interp = interp1(x, y, x_interp, 'linear')
y_interp = interp1(x, y, x_interp, 'spline')
Polynomials
y_vector = polyval(coeff, x_vector)
coeff = conv(coeff1, coeff2)
coeff = polyfit(x_vector, y_vector, degree)
Optimization and Root Finding
r_vector = roots(coeff)
r = fzero(fhandle, guess)
r = fzero(fhandle, [l1, l2])
[x_value, function_value] = fminbnd(fhandle, x1, x2)
Plotting
subplot(r,c,z)
plot(x_vector, y_vector, format string)
loglog(x_vector, y_vector, format string)
semilogx(x_vector, y_vector, format string)
semilogy(x_vector, y_vector, format string)
fplot(fhandle, [x1, x2])
ezplot(symbolic_expression, [x1, x2])
ezplot(symbolic_expression, symbolic_expression, [t1, t2])
plot3(x, y, z)
[x_array,y_array] = meshgrid(x_range, y_range)
mesh(x_array, y_array, z_array)
[c, handle] = contour(x_array, y_array, z_array)
clabel(c, handle)
num = hist(data, bin) hist(data, bins)
Symbolic Toolbox
syms x y
x_numeric = double(x_symbolic)
value = subs(symbolic expression, variable, value)
value = subs(symbolic expression, {variables}, {values})
value = solve(symbolic_expression)
value = solve(symbolic_expression, var)
[x1,x2,x3,x4] = solve(sym_eqn, sym_eqn, sym_eqn, sym_eqn)
expression = diff(symbolic_expression, variable)
expression = int(symbolic_expression, variable)
expression = int(symbolic_expression, variable, a, b)
Unlock document

This preview shows half of the first page of the document.
Unlock all 1 pages and 3 million more documents.

## Document Summary

[value_max, index] = max(vec) array = rand(5, 2) Vector functions total = sum(vec) num = length(vec) array = randi([1, 6], 5, 2) Find and logical index = find(logical expression) index = findstr(target_string, search_string) Character arrays string = num2str(numeric value) numeric value = str2num(character vector) Cell arrays cell = {elements} element = cell{index} string = char(cell{index}) = textread(filename, "%s%f etc. ") numeric_array = dlmread(filename) fid = fopen(filename) cell_array = textscan(fid, "%s%f%f") fclose(fid) I = trapz(x_vector, y_vector) dydx_vector = gradient(y_vector, x_vector) der_coeff = polyder(coeff) int_coeff = polyint(coeff) Interpolation y_interp = interp1(x, y, x_interp, "linear") y_interp = interp1(x, y, x_interp, "spline") Polynomials y_vector = polyval(coeff, x_vector) coeff = conv(coeff1, coeff2) coeff = polyfit(x_vector, y_vector, degree) Optimization and root finding r_vector = roots(coeff) r = fzero(fhandle, guess) r = fzero(fhandle, [l1, l2]) Plotting subplot(r,c,z) plot(x_vector, y_vector, format string) loglog(x_vector, y_vector, format string) semilogx(x_vector, y_vector, format string) semilogy(x_vector, y_vector, format string) fplot(fhandle, [x1, x2]) ezplot(symbolic_expression, [x1, x2]) ezplot(symbolic_expression, symbolic_expression, [t1, t2]) plot3(x, y, z)