Skip to content

Instantly share code, notes, and snippets.

@jalachniet
jalachniet / dblint.m
Created February 22, 2020 11:54
Octave function file for dblquad on nonrectangular domain
% function file 'dblint.m'
% evaluates dblquad(f, x1, x2, y1, y2)
% where f is an anonymous function of x and y
% y1 and y2 are anonymous functions of x
% x1 and x2 are real numbers
function val = dblint(f, x1, x2, y1, y2)
f2 = @(x, u) f(x, y1(x) + u.*(y2(x) - y1(x))) .* (y2(x) - y1(x));
val = dblquad(f2, x1, x2, 0, 1);
end
@jalachniet
jalachniet / linReg.m
Created February 22, 2020 11:53
Octave function file linReg.m: runs a standard linear regression analysis
% function file 'linReg.m' runs a standard linear regression analysis
% syntax: [P r] = linReg(x, y)
% displays regression equation and correlation data, draws scatter plot
% optional return values P: regression equation, r: correlation coefficient
function [P r] = linReg(x, y)
% calculate regression and correlation
P = polyfit(x, y, 1);
r = corr(x, y);
@jalachniet
jalachniet / cave_spline.m
Created February 22, 2020 11:52
Octave script for Project 7.5 in Introduction to GNU Octave book
% script file 'cave_spline.m'
% generates spline curves for walls, ceiling, and floor
% plots plan and profile views of survey line and spline model
% requires 10x1 station coordinate vectors x, y, and z and 10x4 lrud data matrix
% extract left, right, up, down from lrud data matrix
load csurvey_data.txt
L = lrud(:, 1);
R = lrud(:, 2);
U = lrud(:, 3);
@jalachniet
jalachniet / csurvey_data.txt
Created February 22, 2020 11:51
Cave survey data for project 7.5 in Introduction to GNU Octave book
% Created by Octave 5.1.0, Wed Feb 19 09:02:40 2020 GMT <unknown@jlachniet-LT>
% name: data
% type: matrix
% rows: 9
% columns: 3
30.05 248.5 -15.5
10.3 237.5 -25.5
3.2 245 11
17 269 -5
10 271 -10
@jalachniet
jalachniet / mesh2stl.m
Last active December 4, 2024 20:33
meshgrid to stl function for GNU Octave
function mesh2stl(filename, X, Y, Z, delta)
%MESH2STL writes an .stl (STereoLithography) file from meshgrid variables
% mesh2stl('filename', X, Y, Z)
% produces a triangulated mesh from meshgrid variables X, Y, Z
% and writes output to 'filename' in stl format
% --X, Y, Z must be two dimensional arrays of the same size
% --optional: if delta is provided, produce a solid block from the graph
% of surface z = f(x, y)
% where 'delta' gives minimum thickness between base of block
% and graph of surface