Lab13 - A1. fH=@(x) cos(10.*x).^2-10.*x.*sin(20.*x);...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: A1. fH=@(x) cos(10.*x).^2-10.*x.*sin(20.*x); x=linspace(0,pi,300); der = feval(fH,x); plot(x,der) str=sprintf('values of the derivative of x*cos^2(10x)\n at the corresponding value of x'); title(str) xlabel('x') ylabel('value of the derivative') 0.5 1 1.5 2 2.5 3 3.5-30-20-10 10 20 30 40 values of the derivative of x*cos 2 (10x) at the corresponding value of x x value of the derivative A2. clear all hFunc=@(x) x.*cos(10.*x).^2; hFuncDer=@(x) cos(10.*x).^2-10.*x.*sin(20.*x); x1=linspace(0,pi,300); der = feval(hFuncDer,x1); h=[.2,.1,.05,.01]; figure for i=1:length(h) x=0:h(i):pi; m=length(x); n=1; der_approx(n)=(feval(hFunc, (x(n)+h(i)))-feval(hFunc, x(n)))/(h(i)); for n=2:(m-1) der_approx(n)=(feval(hFunc, (x(n)+h(i)))-feval(hFunc, x(n)-h(i)))/(2*h(i)); end n=m; der_approx(n)=(feval(hFunc, x(n))-feval(hFunc, (x(n)-h(i))))/(h(i)); subplot(2,2,i) plot(x1,der,'r:') hold on plot(x,der_approx,'b-') str=sprintf('approximate and actual values of the derivative of x*cos(10x)^2\n with an interval width of %5.2f',h(i)); title(str) xlabel('x') ylabel('value of the derivative')...
View Full Document

This note was uploaded on 03/13/2009 for the course MECHE chem1a taught by Professor Stacy during the Spring '09 term at American College of Gastroenterology.

Page1 / 5

Lab13 - A1. fH=@(x) cos(10.*x).^2-10.*x.*sin(20.*x);...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online