Tuesday, July 7, 2020

Octave - Symbolic calculation - Plot function and its derivetive

This symbilic script get input a function f(x), and the order n of the derivetive requsted.
The script plot the function f(x) and the order n derivetive.

Download the file plot_derive_sym_order_n.m

% This script plot derivetive fd(x) of the function f(x).
% The script use the function_handle function to create numeric
% function ffd from dff(x).

pkg load symbolic
setenv PYTHON C:\ProgramData\Anaconda3\pythonw.exe

disp('Order of derivetive:')
n = 2
% Declare symbolic variable x
syms x;

disp('The function f(x):')
% Input the function f(x) here:
f = sin(x) + cos(x)+ x^2*sin(x)

disp('The n order derivetive fd(x) of the function f(x):')
% The derivative of the function f:
% fd(x) = f'(x)
fd(1) = diff(f,x);
i1 = 2;
while i1<=n
      fd(i1) = diff(fd(i1-1), x);
      i1++;
endwhile
fd(n)
% Convert symbolic function fd(x) to numeric function dff(x):
dff = function_handle(fd(n));

x=-2*pi:0.1:2*pi;
y= dff(x);
plot(x,y)
grid
xlabel('x')
ylabel('fd order n(x)')

Output






No comments:

Post a Comment

Featured Post

Solve simple Absolute Value Inequality

  Exam - BARTON COLLEGE PRACTICE PLACEMENT TEST Ex. 39 Exercise: The inequality |8 - x| < 8   is equivalent to:   a) x < 0 b) x &g...