Truss optimization, read data file

6 views (last 30 days)
Rita Akonobi
Rita Akonobi on 15 Oct 2020
Hi all , Please I am trying to optimize a one bar element with one dof using matlab just test run my code and compare with my analytical answer but it's not working. I have attached the datafile and the code below, please help me
%datafile
TITLE= ONEBAR_ELEMENT
ELEMENTS=1
1 1 2 0.00361 1.79e-6
NODE COORDINATES =`2
1 0.0 0.0
2 4.0 0.0
NODES_WITH_PRESCRIBED_DISPLACEMENTS = 2
1 11 0.000 0.000
2 10 0.000 0.000
YOUNG_MODULUS =210000000.0
YIELD STRESS =100000.0
DENSITY =8050
THRESH HOLD FREQUENCY =2.5
NODES_WITH_POINT_LOAD = 0
PLOTTING_AMPLIFICATION_FACTOR =30
NODES_WITH_VARIABLE_COORDINATES = 1
2 01 5.0 1.0 16.0 6.0
DEFLECTION_LIMIT = 1
2 11 0.01 0.03
%code
function [coorddofvar,fixeddata] = truss2D_readdata(filename)
%
% Set some basic variables
% ========================
% Number of degrees of freedom per node
ndofn=2;
% Number of nodes of the element
nnode=2;
%
% Read information from data file
% ===============================
%
fid = fopen(filename, 'r');
title = fscanf(fid, 'TITLE = %s',1);
%
% Total number of elements in the mesh
nelem = fscanf(fid, '\nELEMENTS = %d', 1);
%
%Read Table of connectivities
%
lnods = fscanf(fid, '\n%d %d %d %f %f', [nnode+3,nelem]);
lnods = lnods';
sortrows(lnods,1);
%...cross-sectional areas
csarea = lnods(:,4);
%...second moment of areas
sndmoa = lnods(:,5);
%...store only connectivities in lnods
lnods = lnods(:,2:nnode+1);
%...create table of element global degrees of freedom
eldofX = lnods*ndofn-1;
eldofY = lnods*ndofn;
eldofs = [ eldofX(:,1) eldofY(:,1) eldofX(:,2) eldofY(:,2) ];
%
% Read Nodal coordinates
%
npoin = fscanf(fid, '\nNODE_COORDINATES = %d', 1);
coord = fscanf(fid, '\n%d %f %f', [3, npoin]);
coord = coord';sortrows(coord,1);nodnumbers=coord(:,1);
coord = coord(:,2:3);
%...create table of nodal degrees of freedom
nodofs = [ nodnumbers*ndofn-1 nodnumbers*ndofn ];
%
This is the error I get
Error using matlab.internal.math.sortrowsParseInputs
Column sorting vector must contain integers with absolute value between 1 and the number of columns in the first argument.
Error in sortrows (line 64)
[col, nanflag, compareflag] = matlab.internal.math.sortrowsParseInputs(ismatrix(A),size(A,2),A,varargin{:});
Error in truss2D_readdata (line 46)
coord = coord';sortrows(coord,1);nodnumbers=coord(:,1);
Error in truss2D_optimization (line 19)
[coorddofvar0,fixeddata] = truss2D_readdata(filename);

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!