Gistlib Logo

gistlib

other matlab categories

substitution code snippets in matlab

apply 'subs' function first to substitute values for variables in matlab
what does this code do? syms x f = exp(x); % function f(x) = exp(x) df = diff(f, x); % calculatet the derivative of f(x) df_value = subs(df, x, 1); % substitute x = 1 in the derivative df_value in matlab
what is this code doing? % define f(x) symbolically syms x f = x; % take the derivative fp = diff(f); % evaluate at x = 1 fprime_at1 = subs(fp, 1); % print result disp(fprime_at1) in matlab

gistlibby LogSnag