Posts

Integration by Parts

Image
When find the solution through the Simpson rule for " I" we must have to choose the step size neither small nor large to get the accurate answer. It means we have to limit the number of sub segments for the higher accuracy. If we select large number of sub segments it should affect to increase the round off error, and if we choose small number of sub segments we can’t get exact solution. There I used multiple segments Simpson 1/3 rule and Simpson 3/8 rule to solve above equation. Because Simpson 1/3 only works for even number of segments and Simpson 3/8 works for multiplication of 3 segments. Multiple segments Simpson 1/3 rule Multiple segments Simpson 3/8 rule According to my program user can select the number of segments (n) as they want. When we apply a = 0, b = 1, assume n = 50 segments, h = (1-0 )/50 we can do the calculation in below progress. Here is the result from Simpson 1/3 rule.    When above constant values apply to Simpson 3/8 rule we c...

Integration of cos(x)

Image
We can find analytical value as below, The solution from the " I"  in above range through the Simpson rule we can get 0.00000 as an approximation value. There we can’t calculate the absolute relative true error. Because the actual value of the integration of cos(x) from 0 to 180 degrees it gets zero. If we will find absolute relative approximation error there should be happened division by zero. The most optimum value of the “h” should be an average value such as “0.01”. It means we should select average number of segments as 48 or 54. Because if we select very large h it decreases the number of segments. As a result we can’t get accurate value. And if we select very small “h” it increases the number of segments. But it should affect to increase the round-off error. That is the reason for we must have to select average value of number of segments to get “h”. Implementation in FORTRAN 1.)Do the compilation as below.     gfortran -ffree-form s...

Text-to-Speech converter

Image
A speech recognition application will typically perform the following basic operations:  Initialize the speech recognizer.  Create a speech recognition grammar.  Load the grammar into the speech recognizer. Register for speech recognition event notification. Create a handler for the speech recognition event. Create a new project in Visual Studio 2010 via select the  File Menu  > New Project Browse to other languagues Select visual basic and windows application enter Name as TextToSpeechVB. when the project is created you have to add a reference to the System.Speech.dll under .NET Tab. Now design the form in following manner. 1. ComboBox control(cmbInstalled) - to list all available installed voices 2. Button Control(btnStart) - To starting the Text-to-Speech 3. Button Control(btnEnd) - To stop the Text-to-Speech 4. Track Bar control(btnRate) - to control the Text-to-Speech speed rate. 5. Trach Bar Control( btnVolume)- to ...

Memory allocation/deallocation routines malloc() and free()

Image
According to my declaration, allocate the 50000 block of array. If memory block is available on the array, the program allocates a block from the array according to specify size.    Here I used the array data structure to implement the heap. In this code taken large contiguous buffer which used to allocate all the spaces associate with the NewMalloc() function. There doesn't allocate the same region of memory to two different NewMalloc() . Initially all 50000 bytes are free in this array. NewMalloc()              It takes one integer argument which represents the size and return a pointer to a contiguous region of that many bytes.              Now call to NewMalloc(60) . There we expect to allocate the first 60 bytes and return a pointer to the caller. Actually in the array allocates 68-bytes for that region. Because I maintain a meta data that k...

simple shell in C

This shell is called mosh (My Own Shell). When invoke, it should be able to read a command typed on its prompt ($) and execute it in a new process. It should also have a shell variable similar to PATH in bash. Shell variables are set as follows: PATH=/usr/bin:/bin The executable for the command is searched in the directories in the path and the first one found should be executed. mosh should also be able to handle pipes (not more than one pipe) similar to bash. Implementation in C #include <stdio.h> #include <unistd.h> #include <string.h> #include <stdlib.h> #include <sys/types.h> #define INPUT_SIZE 512 #define BUF_SIZE 10 char** split_String(char *input_ptr,char *buffer[BUF_SIZE],int *n_args); /** *Main function of the shell */ int main(){     char input[INPUT_SIZE];     char *buffer[BUF_SIZE];     char *pipe_forw[BUF_SIZE];     char *ext_array[BUF_SIZE];   ...

Remort Shell

The client program running on the client computer should connect to the server program running on the server computer. Then the client program should prompt for commands from the user, make them run on the server computer and print results back on the client computer's screen. This command-result sequence should run in a loop so that a number of commands can get run on the server. When the user enters the text "exit" on the client program the system should terminate. Implementation in C client.c /* compile Command : gcc -o client client.c                   ./client */ #include  <sys/types.h> #include  <sys/socket.h> #include  <sys/un.h> #include  <stdio.h> #include  <netinet/in.h> #include  <netdb.h> #include <stdlib.h> #define  PORT  1030    /* addr to connect */ #define  HOST  "localhost" ...

Simple pipe implementation

#include <stdio.h> #include <unistd.h> #include <stdlib.h> int main(){     int pfds[2], status;     char *com1[]={"ls","-a",NULL};     char *com2[]={"sort",NULL};     switch(fork()){         case -1:              printf("Error has been occured");             exit(1);         case 0:             break;//Run the child         default:             wait(&status);//Parent is waiting until child exit             return (status);          }     if(pipe(pfds)<0)         exit(1);     s...