homework_8_derek_rampal

homework_8_derek_rampal - Derek Rampal HW 8 % Derek Rampal...

This preview shows pages 1–3. Sign up to view the full content.

Derek Rampal HW 8 % Derek Rampal % % main % % % x^2(1 - cos x cosh x) - g sin x sinh x = 0 format long ; a1 = .1; b1 = 10; g = .1; counter = 0; answer = zeros(30,4); func = inline( 'x^2*(1-cos(x)*cosh(x))-g*sin(x)*sinh(x)' , 'x' , 'g' ); for x = g:.1:3 counter = counter + 1; answer(counter,1)=x; [apts,bpts] = brute(func,a1,b1,.1,3,x); [answer(counter,2),err,fc] = bisect2(func,apts(1),bpts(1),1e-12,x); [answer(counter,3),err,fc] = bisect2(func,apts(2),bpts(2),1e-12,x); [answer(counter,4),err,fc] = bisect2(func,apts(3),bpts(3),1e-12,x); end ; answer functions: 1. % Derek Rampal % bisect2 % % pass: % % a,b for interval, % delta is tolerance, % y is second variable for func % returns guess for root, error in calculation, and the function value function [c,error,yc] = bisect2(func,a,b,delta,y) ya = feval(func,a,y); yb = feval(func,b,y); while ( b-a >= delta) c=(a+b)/2; yc=feval(func,c,y); if yc == 0 a=c; b=c; elseif (sign(yb) == sign(yc)) b=c; yb=yc; else a=c; ya=yc;

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
end ; end ; error = b-a;
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/19/2009 for the course MATH numerical taught by Professor Ford during the Spring '09 term at FAU.

Page1 / 3

homework_8_derek_rampal - Derek Rampal HW 8 % Derek Rampal...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online