Sunday, January 12, 2020

MATLAB Symbolic pacage

01. Differentiation and Integration with symbolic package.

study :- syms, symfun

%----------------------------ScriptStartHere---------------------------------------------
clear all
clc

syms x                         % create symbolic variable
f=symfun(x^2,x)         % create symmbolic fuunction

df=symfun(diff(f,x),x)       %derivative of f with respect to x
intf=symfun(int(f,x),x)      %intigration of f with respect to x

hold on
ez1=ezplot (f,[-10,10])
ez2=ezplot(df,[-10,10])
ez3=ezplot(intf,[-10,10])
set(ez1,'color' ,[1 1 0])      % yellow color
set(ez2, 'color', [0 1 0])    % Green colour
set(ez3, 'color', [0 0 0])    % Black colour
%----------------------------End---------------------------------------------------------










once you run the above code Mathlab will give the answer as bellow


                df(x) = 2*x
                intf(x) = x^3/3




RGB Triplet
Short Name
Long Name
[1 1 0]
y
yellow
[1 0 1]
m
magenta
[0 1 1]
c
cyan
[1 0 0]
r
red
[0 1 0]
g
green
[0 0 1]
b
blue
[1 1 1]
w
white
[0 0 0]
k
black


2.

%----------------------------ScriptStartHere---------------------------------------------
clear all
clc
syms x m n a b ao;
assume(n,'integer');
assumeAlso(n>0);
assume(m,'integer');
assumeAlso(m>0)

f=symfun(x*log(abs(x)),x)

T=20;
l=T/2;

ao=int(f,x,-l,l)/T
a=symfun(int(f(x)*cos(pi*n*x/l),-l,l)/l,n)
b=symfun(int(f(x)*sin(pi*n*x/l),-l,l)/l,n)

appf=symfun(symsum(a(n)*cos(n*pi*x/l)+b(n)*sin(n*pi*x/l),n,1,m)+ao,[x,m])

ezplot(f,[-10,10])
hold on
ezplot(appf(x,20),[-20,20])
%----------------------------End---------------------------------------------------------

No comments:

Search This Blog