Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 37

NUMERICAL COMPITENCY FOR MECHANICAL ENGINEERS

COURSE CODE : 17ME2206


LAB

Submitted by:
p.chakradhar(170070256)
TOPIC

DECLARATION OF MATRIX AND OPERATIONS

DATE:27-12-19
DECLARATION OF MATRIX AND OPERATION DATE: 29-
12-18

SUB TOPICS:
Declaration of Matrix
CODE:
A=[16 15 14 13;12 11 10 9;8 7 6 5;4 3 2 1]
B=[1 2 2 3;22 2 2 2;3 1 2 2;4 1 1 2]

Operation of Matrix (Addition , Subraction , Multiplication , Inverse Matrix ,


Division)
CODE :
A=[16 15 14 13;12 11 10 9;8 7 6 5;4 3 2 1]
B=[1 2 2 3;22 2 2 2;3 1 2 2;4 1 1 2]
C=A*B
D=[1 2 3 4;5 6 7 8;9 10 11 12;13 14 15 16]
E=A-D
F=A/5
A= inv (B)*C
inv (B)

ans =

-0.0714 0.0357 0.0000 0.0714


1.3571 0.3214 -1.0000 -1.3571
-0.0714 0.0357 1.0000 -0.9286
-0.5000 -0.2500 0.0000 1.5000
SOLVING OF EQAUTION USING SOLVE COMMAND

[x,y,z]=solve('x+3*y+5*z=5','4*x+y+6*z=10','2*x+7*y+z=8')

OUTPUT-
[x,y,z]=solve('x+3*y+5*z=5','4*x+y+6*z=10','2*x+7*y+z=8')

x=

219/113
y=

62/113

z=

32/113
FINDING ROOTS OF POLYNOMIAL :

CODE:

P=[5 2 1 0 1 8];
roots(P)

RESULT:-
-1.1142 + 0.0000i
-0.4413 + 1.0530i
-0.4413 - 1.0530i
0.7984 + 0.6812i
0.7984 - 0.6812i
TOPIC

INTERSECTION OF CURVES

DATE : 21-1-19
INTRODUCTION TO CONTOUR PLOT:
DATE:3-1-19
CODE:
x=-1:0.01:1;
y=x;
[X,Y]=meshgrid(x);
z1=40*sin(10*X)+40*cos(10*Y);
z2=zeros(201,201);
surfc(X,Y,z1);
hold on
surfc(X,Y,z2);
hold on
contour(X,Y,z1)
INTERSECTION OF SIN CURVES
DATE:5-1-19

CODE:

x=-3:0.5:10; %DECLARING THE X RANGE


y1=40*sin(10*x); % CALCULATING THE Y1(X)
y2=zeros(length(x));% CALCULATING THE Y2(X)

%% PLOTTING COMMANDS BEGIN HERE


figure(45)
plot(x,y1,'b');% PLOTTING X AND Y1(X)
hold on; %% USED TO PLOT MULTIPLE PLOTS
grid on;%% GRIDS ARE DISPLAYED
xlabel('independent variable x');%% USED TO DECLARE X VARIABLE
ylabel('dependent variable y'); %% USED TO DECLARE
title('intersection of two curves');
plot (x,y2,'r'); %% PLOTTING X AND Y2(x)
INTERSECTION OF SINUSOIDAL CURVE WITH A HORIZANTAL PLANE

CODE:
x=-1:0.01:1;
y=x; • Output :
[X,Y]=meshgrid(x);
z1=40*sin(10*X)+40*cos(
10*Y);
z2=30*X+4*Y-60;
surfc(X,Y,z1)
hold on
surfc(X,Y,z2)
hold on;
%contour(X,Y,z1);
figure(2)
contour(X,Y,(z1))
figure(5)
contour(X,Y,(z2))
TOPIC

EIGEN VALUES

DATE : 28-1-19
EIGEN VALUES: DATE:10-
1-19

CODE:
sigma=[110 -30 0;-30 30 0;0 0 0];
eig(sigma)
sigma1=[110 -30 0;0 30 0;0 0 0];
eig(sigma1)

tau1=0.5*((eig(sigma)(2))-(eig(sigma)(3)))
tau2=0.5*((eig(sigma)(1))-(eig(sigma)(3)))
tau3=0.5*((eig(sigma)(1))-(eig(sigma)(2)))

ans =

110
30
0
TOPIC

SIMULINK

DATE : 4-2-19
SIMULINK:
DATE:24-1-19

CODE:
mass=-1;
M=1/mass;
C=1

C=1

K=100;
TOPIC

RK4 SOLVER

DATE : 25-2-19
ANS:

m =2

RK4 METHOD: DATE:7-2-19 k = 1

c =0.3000
CODE:
delta_t =1
global m k c F_o t_o t_initial =0
m=2
k=1 t_final =10
c=0.3 F_o =2
delta_t=1
t_initial=0  t_o = 3.1416
t_final=10 tspan =
F_o=2
t_o=pi 
tspan=[t_initial;delta_t;t_final]
 0
X_initial=[0;0]
[t,y]=ode45(Rk4_myfun,tspan,X_initial)  1

 10

 X_initial =

 0

 0
RK4 METHOD:

CODE:

global m c k
m=2;
c=0.3;
k=1;
tini=0;
tfin=10;
delta_t=1;
tspan=[tini: delta_t:tfin];
xini=[ 0.02;0 ];
[t,Y]=ode45('myfunc',tspan,xini);
figure(1);
plot(tspan,Y);
Y =
 -0.0032
 -0.0041
Y =
 -0.0035
Y = Y=
 -0.0039
0
-0.0100 Y =
0.0001  -0.0037
Y=  -0.0038
-0.0051
Y =
-0.0000
-0.0100 
 -0.0043
Y=  -0.0033
Y =
-0.0001 Y=
-0.0100
 -0.0044
-0.0021  -0.0032
Y=
-0.0045 Y =
-0.0002
 -0.0045
-0.0100
 -0.0031

Y= 

Y = 
-0.0002
-0.0100 Y =

-0.0021  -0.0046
-0.0043  -0.0031
TOPIC

PDE TOOL BOX

DATE : 11-3-19
PDE TOOL BOX: DATE:31-1-19

CODE:

% This script is written and read by pdetool and should NOT be edited.
% There are two recommended alternatives:
% 1) Export the required variables from pdetool and create a MATLAB script
% to perform operations on these.
% 2) Define the problem completely using a MATLAB script. See
% http://www.mathworks.com/help/pde/examples/index.html for examples
% of this approach.
function pdemodel
[pde_fig,ax]=pdeinit;
pdetool('appl_cb',1);
set(ax,'DataAspectRatio',[1 1 1]);
set(ax,'PlotBoxAspectRatio',[2 1 2]);
set(ax,'XLimMode','auto');
set(ax,'YLimMode','auto');
set(ax,'XTickMode','auto');
set(ax,'YTickMode','auto');

% Geometry description:
pderect([0 2 1 0],'mydomain');
set(findobj(get(pde_fig,'Children'),'Tag','PDEEval'),'String','mydomain')

% Boundary conditions:
pdetool('changemode',0)
pdesetbd(4,...
'dir',...
1,...
'1',...
'30’)
pdesetbd(3,...
'neu',...
1,...
'0',...
'0')
pdesetbd(2,...
'dir',...
1,...
'1',...
'5')
pdesetbd(1,...
'neu',...
1,...
'0',...
'0')

% Mesh generation:
setappdata(pde_fig,'Hgrad',1.3);
setappdata(pde_fig,'refinemethod','regular');
setappdata(pde_fig,'jiggle',char('on','mean',''));
setappdata(pde_fig,'MesherVersion','preR2013a');
pdetool('initmesh')
pdetool('refine')
pdetool('jiggle')
% PDE coefficients:
% PDE coefficients:
pdeseteq(1,...
'1.0',...
'2',...
'0',...
'1.0',...
'0:10',...
'0.0',...
'0.0',...
'[0 100]')
setappdata(pde_fig,'currparam',...
['1.0';...
'2 ';...
'0 ';...
'1.0'])
% Solve parameters:
setappdata(pde_fig,'solveparam',...
char('0','1008','10','pdeadworst',...
'0.5','longest','0','1E-4','','fixed','Inf'))

% Plotflags and user data strings:


setappdata(pde_fig,'plotflags',[1 1 1 1 1 1 1 1 0 0 0 1 1 0 0 0 0 1]);
setappdata(pde_fig,'colstring','');
setappdata(pde_fig,'arrowstring','');
setappdata(pde_fig,'deformstring','');
setappdata(pde_fig,'heightstring','');

% Solve PDE:
pdetool('solve')
TOPIC

OPTIMISATION TOOL BOX

DATE : 18-3-19
• OPTIMISATION FUNCTION FILE

OPTIMISATION • function [y] = rosenbrocks(x)
TOOL BOX • y=100*(x(2)-x(1)^2)^2+(1-x(1))^2;
• end
F MINCON :

•1
GENETIC
ALGORITHM
OPTIMISATION DATE:18-3-19

CODE:

function[y]=obj(x)
y=x.^2+3*x+2;

end
TOPIC

APP DEVELOPMENT

DATE : 25-3-19
APP DEVOLOPEMENT:
CODE:
function varargout = app_dev(varargin)
% APP_DEV MATLAB code for app_dev.fig
% APP_DEV, by itself, creates a new APP_DEV or raises the existing
% singleton*.
%
% H = APP_DEV returns the handle to a new APP_DEV or the handle to
% the existing singleton*.
%
% APP_DEV('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in APP_DEV.M with the given input arguments.
%
% APP_DEV('Property','Value',...) creates a new APP_DEV or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before app_dev_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to app_dev_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help app_dev

% Last Modified by GUIDE v2.5 23-Mar-2019 12:31:29


% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @app_dev_OpeningFcn, ...
'gui_OutputFcn', @app_dev_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT

% --- Executes just before app_dev is made visible.


function app_dev_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to app_dev (see VARARGIN)
% Choose default command line output for app_dev
handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

% UIWAIT makes app_dev wait for user response (see UIRESUME)


% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = app_dev_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure


varargout{1} = handles.output;

% --- Executes on button press in add.

function add_Callback(hObject, eventdata, handles)


% hObject handle to add (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
d1=str2double(get(handles.a,'String'));
d2=str2double(get(handles.b,'String'));
c=d1+d2;
set(handles.result,'string',num2str(c));

function b_Callback(hObject, eventdata, handles)


% hObject handle to b (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of b as text


% str2double(get(hObject,'String')) returns contents of b as a double

% --- Executes during object creation, after setting all properties.


function b_CreateFcn(hObject, eventdata, handles)
% hObject handle to b (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function a_Callback(hObject, eventdata, handles)
% hObject handle to a (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of a as text


% str2double(get(hObject,'String')) returns contents of a as a double

% --- Executes during object creation, after setting all properties.


function a_CreateFcn(hObject, eventdata, handles)
% hObject handle to a (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
clc
OUTPUT

You might also like