# Tutor profile: Krishna S.

## Questions

### Subject: MATLAB

Convolute two identical rectangular pulses? 1- Write a function rect(t) 2- Write a program to find two convolution of two identical rectangular pulses which are defined in the interval [-0.5 ,0.5 ] 3- plot both input and output

The following is code for the above question, comments are included for better understanding of question. function [ ] = task1aks( ) %function for rectangle function [ n ] = rectangle( t ) n=zeros(1,size(t,2)); for i=1:length(t) n(i)=0; if (t(i)>=-0.5) && (t(i)<=0.5) n(i)=1; end end end %initial values fs=100; t=-5:1/fs:5; x=rectangle(t); %convoluting things y=conv(x,x,'same')/fs; figure subplot(2,1,1); plot(t,x); title('Input_value'); subplot(2,1,2); plot(t,y); title('Output_value'); end

### Subject: Java Programming

how to find out the middle element in a linked list in a single pass(in one loop through the list)?

The following is the code for above, comments are included in code for better understanding of the solution. /** * Java program to find middle element of linked list in one pass. * In order to find middle element of linked list we need to find length first * but since we can only traverse linked list one time, we will use two pointers * one which we will increment on each iteration while other which will be * increased every second iteration. so when first pointer will point to the * last of linked list, second will be pointing to the middle element of linked list */ public class LinkedListTest { public static void main(String args[]) { //creating LinkedList with 5 elements including head LinkedList linkedList = new LinkedList(); LinkedList.Node head = linkedList.head(); linkedList.add( new LinkedList.Node("1")); linkedList.add( new LinkedList.Node("2")); linkedList.add( new LinkedList.Node("3")); linkedList.add( new LinkedList.Node("4")); //finding middle element of LinkedList in single pass LinkedList.Node current = head; int length = 0; LinkedList.Node middle = head; while(current.next() != null){ length++; if(length%2 ==0){ middle = middle.next(); } current = current.next(); } if(length%2 == 1){ middle = middle.next(); } System.out.println("length of LinkedList: " + length); System.out.println("middle element of LinkedList : " + middle); } } class LinkedList{ private Node head; private Node tail; public LinkedList(){ this.head = new Node("head"); tail = head; } public Node head(){ return head; } public void add(Node node){ tail.next = node; tail = node; } public static class Node{ private Node next; private String data; public Node(String data){ this.data = data; } public String data() { return data; } public void setData(String data) { this.data = data; } public Node next() { return next; } public void setNext(Node next) { this.next = next; } public String toString(){ return this.data; } } }

### Subject: Electrical Engineering

Why is only sine wave used to represent electrical waves in equations, not square or cosineor other forms of waves?

It is not by choice that we use sine wave as the standard form. It is also not because sine wave has a maximum minimum and as such a large rms value. Rms value for cosine and ramp waves is also same, but we don't use them, because in the power generation, emf induced produces current in sine wave form only.It is the simplest way we can produce current.

## Contact tutor

needs and Krishna will reply soon.