0% found this document useful (0 votes)
44 views

Varargout Estesi (Varargin) : Function

This document describes a MATLAB code for analyzing a truss structure. It defines functions for creating a graphical user interface (GUI) with input fields for defining the truss geometry and material properties. It also contains functions for assembling the stiffness matrix, applying loads, solving for displacements and stresses, and outputting the results. Key inputs include the modulus of elasticity, cross-sectional area, node coordinates, connectivity, and applied forces. The code solves for displacements, reactions, and member stresses.

Uploaded by

Elizabeth
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

Varargout Estesi (Varargin) : Function

This document describes a MATLAB code for analyzing a truss structure. It defines functions for creating a graphical user interface (GUI) with input fields for defining the truss geometry and material properties. It also contains functions for assembling the stiffness matrix, applying loads, solving for displacements and stresses, and outputting the results. Key inputs include the modulus of elasticity, cross-sectional area, node coordinates, connectivity, and applied forces. The code solves for displacements, reactions, and member stresses.

Uploaded by

Elizabeth
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

function varargout = estesi(varargin)

% ESTESI MATLAB code for estesi.fig


% ESTESI, by itself, creates a new ESTESI or raises the existing
% singleton*.
%
% H = ESTESI returns the handle to a new ESTESI or the handle to
% the existing singleton*.
%
% ESTESI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in ESTESI.M with the given input arguments.
%
% ESTESI('Property','Value',...) creates a new ESTESI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before estesi_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to estesi_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 estesi

% Last Modified by GUIDE v2.5 19-Dec-2017 22:23:08


% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @estesi_OpeningFcn, ...
'gui_OutputFcn', @estesi_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 estesi is made visible.


function estesi_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 estesi (see VARARGIN)

% Choose default command line output for estesi


handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

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


% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = estesi_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;

function elasticidad_Callback(hObject, eventdata, handles)


% hObject handle to elasticidad (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 elasticidad as text
% str2double(get(hObject,'String')) returns contents of elasticidad as
a double

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


function elasticidad_CreateFcn(hObject, eventdata, handles)
% hObject handle to elasticidad (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 area_Callback(hObject, eventdata, handles)


% hObject handle to area (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 area as text


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

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


function area_CreateFcn(hObject, eventdata, handles)
% hObject handle to area (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 fuerza4_Callback(hObject, eventdata, handles)


% hObject handle to fuerza4 (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 fuerza4 as text


% str2double(get(hObject,'String')) returns contents of fuerza4 as a
double
% --- Executes during object creation, after setting all properties.
function fuerza4_CreateFcn(hObject, eventdata, handles)
% hObject handle to fuerza4 (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

% --- Executes on button press in pushbutton1.


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

% E; modulus of elasticity
% A: area of cross section
% L: length of bar

format SHORTENG
E=get(handles.elasticidad,'String');
E=str2num(E);

A=get(handles.area,'String');
A=str2num(A); % area for various sections

EA=E*A;

% generation of coordinates and connectivities


%elementNodes=[ 1 2;1 3;2 3;2 4;1 4;3 4;3 6;4 5;4 6;3 5;5 6];
elementNodes=get(handles.nodo,'String');
elementNodes=str2num(elementNodes);

%nodeCoordinates=[ 0 0;0 3000;3000 0;3000 3000;6000 0;6000 3000];


nodeCoordinates=get(handles.coordenadas,'String');
nodeCoordinates=str2num(nodeCoordinates);

numberElements=size(elementNodes,1);
numberNodes=size(nodeCoordinates,1);

xx=nodeCoordinates(:,1);
yy=nodeCoordinates(:,2);

% for structure:
% displacements: displacement vector
% force : force vector
% stiffness: stiffness matrix
GDof=2*numberNodes;
U=zeros(GDof,1);
force=zeros(GDof,1);
% applied load at node 2
f4=get(handles.fuerza4,'String');
f4=str2num(f4);
force(4)=f4;

f8=get(handles.fuerza8,'String');
f8=str2num(f8);
force(8)=f8;

f12=get(handles.fuerza12,'String');
f12=str2num(f12);
force(12)=f12;

% computation of the system stiffness matrix


[stiffness]=...
formStiffness2Dtruss(GDof,numberElements,...
elementNodes,numberNodes,nodeCoordinates,xx,yy,EA);

% boundary conditions and solution


prescribedDof=[1 2 10]';

% solution
displacements=solution(GDof,prescribedDof,stiffness,force);
us=1:2:2*numberNodes-1;
vs=2:2:2*numberNodes;

% drawing displacements

%figure
%L=xx(2)-xx(1);
%L=node(2,1)-node(1,1);
%XX=displacements(us);YY=displacements(vs);
%dispNorm=max(sqrt(XX.^2+YY.^2));
%scaleFact=2*dispNorm;
%clf
%hold on
%drawingMesh(nodeCoordinates+scaleFact*[XX YY],...
% elementNodes,'L2','k.-');
%drawingMesh(nodeCoordinates,elementNodes,'L2','k.--');

% output displacements/reactions
%outputDisplacementsReactions(displacements,stiffness,...
% GDof,prescribedDof)

% displacements
disp('Displacements')
%displacements=displacements1;
jj=1:GDof; format
[jj' displacements]

% reactions
F=stiffness*displacements;
reactions=F(prescribedDof);
disp('reactions')
[prescribedDof reactions]

% stresses at elements
%---- stresses2Dtruss(numberElements,elementNodes,...
%--- xx,yy,displacements,E)
for e=1:numberElements
indice=elementNodes(e,:);
elementDof=[ indice(1)*2-1 indice(1)*2 indice(2)*2-1 indice(2)*2] ;
xa=xx(indice(2))-xx(indice(1));
ya=yy(indice(2))-yy(indice(1));
length_element=sqrt(xa*xa+ya*ya);
C=xa/length_element;
S=ya/length_element;
sigma(e)=E/length_element* ...
[-C -S C S]*displacements(elementDof);
sigma

cla(handles.plotFig);
plot(handles.plotFig,nodeCoordinates(:,1),nodeCoordinates(:,2),'o');
hold on;

dispXYZ = zeros(length(displacements)/2,2);
dispXYZ(:,1) = displacements(1:2:length(displacements)-1);
dispXYZ(:,2) = displacements(2:2:length(displacements));

display(dispXYZ)
nodeCoDis = nodeCoordinates+dispXYZ;

for i=1:length(elementNodes(:,1))
itmp = elementNodes(i,1);
jtmp = elementNodes(i,2);
xs = [nodeCoordinates(itmp,1) nodeCoordinates(jtmp,1)];
ys = [nodeCoordinates(itmp,2) nodeCoordinates(jtmp,2)];

xd = [nodeCoDis(itmp,1) nodeCoDis(jtmp,1)];
yd = [nodeCoDis(itmp,2) nodeCoDis(jtmp,2)];

plot(handles.plotFig,xs, ys, 'Color', 'black');


plot(handles.plotFig,xd, yd, 'Color', 'red');
end
grid on
axis equal
end

disp('stresses')
sigma'
%%

set(handles.esfuerzos,'String',num2str(sigma'));
set(handles.reacciones,'String',num2str([prescribedDof reactions]));
set(handles.desplazamientos,'String',num2str([jj' displacements]));
function fuerza8_Callback(hObject, eventdata, handles)
% hObject handle to fuerza8 (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 fuerza8 as text


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

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


function fuerza8_CreateFcn(hObject, eventdata, handles)
% hObject handle to fuerza8 (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 fuerza12_Callback(hObject, eventdata, handles)


% hObject handle to fuerza12 (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 fuerza12 as text


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

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


function fuerza12_CreateFcn(hObject, eventdata, handles)
% hObject handle to fuerza12 (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 coordenadas_Callback(hObject, eventdata, handles)


% hObject handle to coordenadas (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 coordenadas as text


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

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


function coordenadas_CreateFcn(hObject, eventdata, handles)
% hObject handle to coordenadas (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 nodo_Callback(hObject, eventdata, handles)


% hObject handle to nodo (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 nodo as text


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

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


function nodo_CreateFcn(hObject, eventdata, handles)
% hObject handle to nodo (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

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


function axes4_CreateFcn(hObject, eventdata, handles)
% hObject handle to axes4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
problem=imread('probfig.PNG');
image(problem)
axis off
% Hint: place code in OpeningFcn to populate axes4

You might also like