Você está na página 1de 3

1.

Declare a 3X3 matrix A= 1 4 6 and 2 6 7 4 0 7 ANS A= [1 4 6; 2 6 7;4 0 7] B= [ 9 8 4;5 4 1;6 4 0]

B= 9 8 4 5 4 1 6 4 0

-sin(pi/2) -tan(pi/6) -(sin(pi/6))^2 + (cos(pi/6))^2 -exp(pi*sqrt(160)) -7*(sqrt(13)+1)/8 2.Create a vector v with 10 elements 1, 2, 3, .10 and compute the following. a=v e^v b= cosv/v c= (v+1)/(v-1) ANS. v=(1:10) a=v.*exp(v) b= ((cos(v)).^2)./v c= (v.^2+1)./(v.^2-1) 3.Plot y= sin x, 0<=x<= 2p, taking 100 linearly spaced points in the given inter val. Label the axes and put plot created by your name . ANS. x=linspace(0,2*pi,100); plot(x,sin(x)) xlabel( x ),ylabel( sin(x) ) title( plot created by drmztech ) 4.Design a MATLAB program that takes an input temperature in degree Fahrenheit, converts it to an absolute temperature in Kelvin and writes out the result ANS. function[temp_k]=temp_conv() temp_f=input('enter the temp in farenheit') temp_k = 5/9*temp_f - 32 + 273.15; 5.Write a matlab program to calculate the sum of cubes of first function[sum]= addition(n) sum=0; for i=1:n sum= sum + i^3; end sum 6.Create MATLAB GUI as per figure edit text1: input = str2num(get(hObject,'String')); %checks to see if input is empty. if so, default input1_editText to zero if (isempty(input)) set(hObject,'String','0') n natural numbers.

end guidata(hObject, handles); --------Pushbutton_add button s callback function: a b % % = get(handles.edit1,'String'); = get(handles.edit2,'String'); a and b are variables of Strings type, and need to be converted to variables of Number type before they can be added together

total = str2num(a) + str2num(b); c = num2str(total); % need to convert the answer back into String type to display it set(handles.edit_result,'String',c); guidata(hObject, handles);

-----------------Pushbutton_sub button s callback function: a b % % = get(handles.edit1,'String'); = get(handles.edit2,'String'); a and b are variables of Strings type, and need to be converted to variables of Number type before they can be added together

total = str2num(a) - str2num(b); c = num2str(total); % need to convert the answer back into String type to display it set(handles.edit_result,'String',c); guidata(hObject, handles); -----------Pushbutton_mul button s callback function: a = get(handles.edit1,'String'); b = get(handles.edit2,'String'); % a and b are variables of Strings type, and need to be converte % to variables of Number type before they can be added together total = str2num(a) * str2num(b); c = num2str(total); % need to convert the answer back into String type to display it set(handles.edit_result,'String',c); guidata(hObject, handles); --------------------------Pushbutton_div button s callback function: a = get(handles.edit1,'String'); b = get(handles.edit2,'String'); % a and b are variables of Strings type, and need to be converted % to variables of Number type before they can be added together total = str2num(a) / str2num(b); c = num2str(total); % need to convert the answer back into String type to display it set(handles.edit_result,'String',c);

guidata(hObject, handles);

Você também pode gostar