Wednesday, January 4, 2017

PID controller with BeagleBone Black using Python

I am adding the python program I have written to control a DC motor using PID control technique. You can get the code from the following link.



Share your suggestions so that I can improve the code. I will explain the working of the code later in this blog, In sha Allah. 

Thanks
Noufal

Monday, April 8, 2013

Numerical Integraion Using Trapezoidal Rule.

The process of evaluating a definite integral from a set of tabulated values of integrand f(t) is called numerical integration. The following MATLAB code gives a generalized illustration of numerical integration using Trapezoidal rule. The algorithm for the same is given in the comments at the beginning of the program. Try it for your own function.

% Integration by Trapezoidal method
% This example shows how you can do numerical integration by Trapizoidal
% method
% The formula for this method is given as ...
% $$ \int\limits_0^{\frac{2\pi}{\omega}}f(t)dt = \frac{h}{2}\left[f(a) +
% 2\sum_{i = 0}^{i = K - 1}f(x) + f(b)\right]$
%
% where a = lower limit of integration, b = upper limit of integration
%
% $h = \frac{a - b}{K}$, where K = no. intervals under consideration
% Here the function is $ f(t) = \frac{1}{1+x^2} $ Here we are integrating
% from 0 to 6, taking 6
% intervals in between.
 
clc;
clear all;
a = 0;
b = 6;
K = 6;
h = (b - a) / K;
t = 0 : .0001 :6;
f = inline('1./(1+t.^2)', 't')
plot(t, f(t),'r','linewidth',2.5)
hold;
t1 = a : h : b;
stem(t1, f(t1),'m','filled','linewidth',2.5)
grid;
out = 0;
for i = 1 : K - 1
    out = out + f(a+i*h);
end
result = (h / 2) * (f (a) + 2 * (out) + f(b))

Thank You

Thursday, March 28, 2013

Installing LaTeX in Windows

To get started with LaTeX, a wonderful document or presentation maker. Follow the steps below
1. Install MikTeX. Use this link. http://mirrors.ctan.org/systems/win32/miktex/setup/basic-miktex-2.8.3761.exe
2. Use this link. http://www.xm1math.net/texmaker/texmakerwin32_install.exe



Happy TeXing....

Wednesday, March 6, 2013

LaTeX Symbols

The important feature of LaTeX is its symbol(Mathematical and Others) handling capability. Here is a list of all symbols that is possible with LaTeX.
Hope you make use of it.
1. symbols-a4.pdf
2. symbols-letter.pdf

Monday, February 11, 2013

Changing MATLAB windows color

Feeling to be colorful...

You can change the MATLAB window color. 

Goto File --> Preferences --> Colors(on the left side) --> Un-check "Use system color"

And change as you wanted...
Try the following. 

1. Terminal



2. Ubuntu


3. Cool


4. Bright



Try your own colors and let me know...



Sunday, February 10, 2013

Newton Raphson Method

Hello everybody...
The following is a sample program to understand finding solution of a non linear equation using Newton Raphson Method. This program is not a generalised one. But you can understand the basic idea of the method and how to implement it using MATLAB. For more information about this method please try this

% This programme is to find the solution of a non linear equation by Newton Raphson method.
% This is not a generalized program
clc;
clear all;
format long;
syms x;
e = 1e-5;                      % setting the tolerance value
dx = e + 1;
f = log(2-x) + x^2;               % enter your function here;
x = 7;                          % initially assumed value of x
count = 0;                      % setting counter to know the no of iterations taken
p = zeros(1,1);
while (abs(dx) > e)             % initialising the iteration and continue until the error is less than tolerance
    dx = eval(f/(diff(f)));     % calculating dx, diff is used for finding the differentiation of the fuction
    x = x - dx                 % updating the value of x
    count = count + 1;          % incrimenting the counter
    p(count) = x;
    drawnow();
    plot(abs(p),'r','linewidth',3);
    grid;
    if (count > 300)
        fprintf('Error...! Solution not converging !!! \n');  % printing the error message
        break;
    end
end
% plot(abs(p));
if (count < 300)
    fprintf('The solution = ');  %printing the result
    x
    fprintf('\nNumber of iteration taken = %d\n',count);
end

Try it for different functions
Thank you...

Wednesday, February 6, 2013

Convolution of two functions

Enter the following code in to your MATLAB editor. You could see how the convolution of two function in calculated. Try the same for your functions.


clc;
clear all;
t = 0  : 0.05 : 4;
x = inline ('(exp(-0.001*t)).*(t >= 0)','t');
h = inline ('(exp(-0.001*t).*(t >= 0)) + (exp(-3*t)).*(t>=0)','t');
dtau = 0.005;
tau = -1:dtau:4;
ti = 0;
tvec = -0.25:0.1:3.75;
y = NaN * zeros (1, length (tvec));
figure(1);
for t= tvec
    ti = ti + 1;
    xh = x(t - tau) .* h(tau);
    y(ti) = sum (xh .* dtau);
    subplot(2,1,1), plot(tau, h(tau), 'k-', tau,x(t-tau),'k--',t,0,'ok');
    axis([tau(1) tau(end) -0.25 3]);
    subplot(2,1,2), plot(tvec, y, 'k', tvec(ti), y(ti),'ok');
    axis([tau(1) tau(end) -0.25 5]);
    drawnow;
    pause(0.1);
end