Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
someting is wrong but ı didnt find it
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
clear,clc
E=200*10^3;
A=100;
L1=1000 ; % for element 1,2,3,5,6,8,9,10
L2=1414.21;% for element 4,7
l(1)=1;
m(1)=0;
l(2)=1;
m(2)=0;
l(3)=0;
m(3)=1;
l(4)=0.514;
m(4)=0.857;
l(5)=0;
m(5)=1;
l(6)=0;
m(6)=1;
l(7)=0.514;
m(7)=0.857;
l(8)=1;
m(8)=0;
l(9)=0;
m(9)=1;
l(10)=1;
m(10)=0;
for i=1:10
K(i)=(E*A/L1)*[l(i)^2, l(i)*m(i), -l(i)^2, -l(i)*m(i);
l(i)*m(i), m(i)^2, -l(i)*m(i), -m(i)^2;
-l(i)^2, -l(i)*m(i), -l(i)^2, l(i)*m(i);
-l(i)*m(i), -m(i)^2, l(i)*m(i), m(i)^2];
end
for i=1:2
K(i)=(E*A/L2)*[l(3*i+1)^2 l(3*i+1)*m(3*i+1) -l(3*i+1)^2 -l(3*i+1)*m(3*i+1);
l(3*i+1)*m(3*i+1) m(3*i+1)^2 -l(3*i+1)*m(3*i+1) -m(3*i+1)^2;
-l(3*i+1)^2 -l(3*i+1)*m(3*i+1) -l(3*i+1)^2 l(3*i+1)*m(3*i+1);
-l(3*i+1)*m(3*i+1) -m(3*i+1)^2 l(3*i+1)*m(3*i+1) m(3*i+1)^2];
end
0 comentarios
Respuestas (4)
Roger Stafford
el 28 de Mayo de 2013
You are expecting the array K to have elements which are themselves arrays. Matlab doesn't like that. Moreover you don't have left brackets to match the right brackets.
0 comentarios
Image Analyst
el 28 de Mayo de 2013
It looks like you're trying to set a single element of K, K(i), equal to a whole 4 by 4 array - you can't do that because K(i) can be only a single number. You can make K a cell array and do that, but not if it's just a regular numerical array.
K{i} = ......
See FAQ on cell arrays if you want to use them: http://matlab.wikia.com/wiki/FAQ#What_is_a_cell_array.3F
1 comentario
Image Analyst
el 28 de Mayo de 2013
OK (your answer below) - did that fix it? I wonder why you go from 1-10 in the first loop and then overwrite elements 1 and 2 in the second loop. Why not start the first loop at 3 and put it after the other loop?
tony karamp
el 28 de Mayo de 2013
Do this:
clear,clc
E=200*10^3;
A=100;
L1=1000 ; % for element 1,2,3,5,6,8,9,10
L2=1414.21;% for element 4,7
l(1)=1;
m(1)=0;
l(2)=1;
m(2)=0;
l(3)=0;
m(3)=1;
l(4)=0.514;
m(4)=0.857;
l(5)=0;
m(5)=1;
l(6)=0;
m(6)=1;
l(7)=0.514;
m(7)=0.857;
l(8)=1;
m(8)=0;
l(9)=0;
m(9)=1;
l(10)=1;
m(10)=0;
for i=1:10
K{i}=(E*A/L1)*[l(i)^2, l(i)*m(i), -l(i)^2, -l(i)*m(i);
l(i)*m(i), m(i)^2, -l(i)*m(i), -m(i)^2;
-l(i)^2, -l(i)*m(i), -l(i)^2, l(i)*m(i);
-l(i)*m(i), -m(i)^2, l(i)*m(i), m(i)^2];
end
for i=1:2
K{i}=(E*A/L2)*[l(3*i+1)^2 l(3*i+1)*m(3*i+1) -l(3*i+1)^2 -l(3*i+1)*m(3*i+1);
l(3*i+1)*m(3*i+1) m(3*i+1)^2 -l(3*i+1)*m(3*i+1) -m(3*i+1)^2;
-l(3*i+1)^2 -l(3*i+1)*m(3*i+1) -l(3*i+1)^2 l(3*i+1)*m(3*i+1);
-l(3*i+1)*m(3*i+1) -m(3*i+1)^2 l(3*i+1)*m(3*i+1) m(3*i+1)^2];
end
0 comentarios
Sean de Wolski
el 28 de Mayo de 2013
Editada: Sean de Wolski
el 28 de Mayo de 2013
Using a cell array for a stiffness matrix is a bad idea. You will eventually need to build the entire global stiffness matrix in order to solve it so you might as well do this right away. Locate where each element belongs in the global matrix and stick it in there based on the index (from coordinates, and connectivities, etc.). Here is an example GUI I wrote to solve for a simply supported beam:
function beam_deflection
%GUI that allows you to apply a load to a simply supported beam with sliders
%
%No inputs
%No outputs
%
%
% Copyright 2013 The MathWorks, Inc.
%
%Build figure:
bgc = [0.8 0.8 0.8]; %Background color
%Figure and axes
hfig = figure('units','pix','position',[500 500 500 400],'color',bgc,...
'menubar','none','numbertitle','off','name','Simply Supported Beam Deflection Under Point Load',...
'resize','off');
movegui(hfig,'center');
axes('parent',hfig,'units','pix','outerposition',[50 50 400 300],...
'xtick',[],'ytick',[],'xcolor',bgc,'ycolor',bgc,'xlim',[-1 11],'ylim',[-5 5]);
%Components
hS = zeros(3,1);
hS(1) = uicontrol('style','slider','units','pix','position',[115 340 289 20],...
'min',0,'max',180,'value',90);
hS(2) = uicontrol('style','slider','units','pix','position',[80 90 20 230],...
'min',-5,'max',5,'value',2);
hS(3) = uicontrol('style','slider','units','pix','position',[115 50 289 20],...
'min',-0.5,'max',10.5,'value',5,'sliderstep',[0.1 0.1]);
line('xdata',0,'ydata',-0.35,'marker','o','markersize',10,'markerfacecolor','b',...
'markeredgecolor','b')
line('xdata',10,'ydata',-0.35,'marker','^','markersize',10,'markerfacecolor','r',...
'markeredgecolor','r')
hBeam = line('xdata',linspace(-0.5,10.5,101),'ydata',zeros(1,101),'linewidth',3);
uicontrol('style','text','units','pix','position',[130 10 260 30],'fontsize',14,...
'string','Point Load Position','backgroundcolor',bgc);
uicontrol('style','text','units','pix','position',[130 360 260 30],'fontsize',14,...
'string','Point Load Angle','backgroundcolor',bgc);
uicontrol('style','text','units','pix','position',[10 190 60 30],'fontsize',14,...
'string','Force','backgroundcolor',bgc);
hArrow = line('xdata',[5 5],'ydata',[0.7 0],'linewidth',1.5,'color','b');
%Handles structure and control
handles = struct('hS',hS,'hBeam',hBeam,'hArrow',hArrow);
set(hS,'callback',{@ctrl, handles})
ctrl([],[],handles);
end
function ctrl(~,~,handles)
%Drives
[force, position, ang] = getFPA(handles.hS); %force position and angle
the_beam = linspace(-0.5,10.5,101);
[~,idx] = min(abs(the_beam-position)); %where are we?
U = solveit(force,ang,idx); %solve for deflection
%Apply changes
set(handles.hBeam,'ydata',U(2:3:end));
set(handles.hBeam,'xdata',U(1:3:end)'+the_beam)
set(handles.hArrow,'ydata',[force*cosd(ang),U(idx*3-1)]);
set(handles.hArrow,'xdata',[position+force*sind(ang),position(1)]);
end
function [force, position, ang] = getFPA(hS)
%Get force position and angle
force = get(hS(2),'value'); %
position = get(hS(3),'value'); %value of position
ang = get(hS(1),'value') - 90; %default is 90
end
function U = solveit(force,ang,idx)
%Solver
F = zeros(303,1); %force [u v theta]
idx = 3*idx; %index of point load
F(idx-2) = -force*sind(ang); %force components
F(idx-1) = -force*cosd(ang);
K = zeros(303); %stiffness matrix preallocate
E = 29000; %ksi
L = 0.11*12; %element length
EAL = E*1.5*L;
I = 3.4;
%element matrix
kel = [EAL 0 0 -EAL 0 0;
0 12*E*I/(L^3) 6*E*I/(L^2) 0 -12*E*I/(L^3) 6*E*I/(L^2);
0 0 4*E*I/L 0 -6*E*I/(L^2) 2*E*I/L;
0 0 0 EAL 0 0;
0 0 0 0 12*E*I/(L^3) -6*E*I/(L^2);
0 0 0 0 0 4*E*I/L];
kel = kel+triu(kel,1)';
%fill in k
for ii = 1:100
idx = (ii*3-2):(ii*3-2)+5;
K(idx,idx) = K(idx,idx) + kel;
end
%Apply boundary conditions
K([16 17 end-16],:) = 0;
K(:,[16 17 end-16]) = 0;
K(16,16) = 1;
K(17,17) = 1;
K(end-16,end-16) = 1;
%solve U
U = K\F;
end
3 comentarios
Sean de Wolski
el 30 de Mayo de 2013
@Tony, No. Though this might not error, it will not create the stiffness matrix he wants which requires various stiffnesses to be added at specific nodes (coordinates). cell2mat will blindly create a matrix that does not contain this information.
La pregunta está cerrada.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!