Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function main
- clc
- format long
- step = 0.01;
- cur_x = 0.0;
- derivs_my_1 = [];
- derivs_my_2 = [];
- derivs_1 = [];
- derivs_2 = [];
- syms xx;
- derivative1 = diff(tan(2 * xx))
- derivative2 = diff(derivative1)
- my_func = @func
- while (cur_x <= 1.0)
- derivs_1 = [derivs_1, vpa(subs(derivative1, xx, cur_x))];
- derivs_2 = [derivs_2, vpa(subs(derivative2, xx, cur_x))];
- derivs_my_1 = [derivs_my_1, calc_deriv(cur_x, my_func, 1)];
- derivs_my_2 = [derivs_my_2, calc_deriv(cur_x, my_func, 2)];
- cur_x = cur_x + step;
- end
- derivs_2
- derivs_my_2
- end
- function F = func(x)
- % write your stupid function here
- F = tan(2 * x);
- end
- function F = calc_deriv(x, func, power)
- increment = 1e-5;
- if power == 1
- F = (func(x + increment) - func(x)) / increment;
- else
- f1 = (func(x + increment) - func(x)) / increment;
- f2 = (func(x + 2 * increment) - func(x + increment)) / increment;
- F = (f1 - f2) / increment;
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement