d2jsp
Log InRegister
d2jsp Forums > Off-Topic > General Chat > Homework Help > Richardson/s Extrapolation In Matlab
Add Reply New Topic New Poll
Member
Posts: 35,671
Joined: Aug 11 2008
Gold: 2,130.00
Oct 11 2014 02:30pm
Code
h = .25;
f = @(x) tan(x);
tol = 0;
f1 = tol + 10^-10
while f1 > tol
f1 = ( f(1+h) - f(1-h) )/ (2*h)
h = h/2
end



http://i.imgur.com/7cOTQIs.jpg

is this how I do it?
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Oct 11 2014 02:47pm
did you test the function by finding the derivative of f(x) = tan(x) at x = 1 to an error tolerance of 10^-10?
Member
Posts: 35,671
Joined: Aug 11 2008
Gold: 2,130.00
Oct 11 2014 03:09pm
um wtf? i change it to this. isnt the syntax for takin derivaitiven.. diff?
Code
h = .25;
f = @(x) tan(x);
df = diff(f);
df(1)
tol = 0;
f1 = tol + 10^-10
while f1 > tol
f1 = ( f(1+h) - f(1-h) )/ (2*h)
h = h/2;
end


and it says error

Code
Error using diff
Function 'diff' is not supported for class 'function_handle'.

Error in homework5_1 (line 9)
df = diff(f);
Member
Posts: 11,885
Joined: May 19 2006
Gold: 1,092.39
Oct 11 2014 04:43pm
cash money
Member
Posts: 35,671
Joined: Aug 11 2008
Gold: 2,130.00
Oct 11 2014 04:51pm
Quote (someone3 @ Oct 11 2014 05:43pm)
cash money


young money cash money??
Member
Posts: 35,671
Joined: Aug 11 2008
Gold: 2,130.00
Oct 11 2014 05:23pm
Code
format long
h = .25;
syms x
f = @(x) tan(x);
df = diff(f(x));
eval(subs(df,1))
tol = 0;
f1 = tol + 10^-10;
while f1 > tol
f1 = ( f(1+h) - f(1-h) )/ (2*h)
h = h/2;
end


my updated code... so how to fix this?
Go Back To Homework Help Topic List
Add Reply New Topic New Poll