1- clc ; clear ; close all ;
1+ close all ;
22
33%% User Inputs & Problem Definition
44% Prompt the user to define the beam's physical properties and loads.
1818exponents = []; % Vector for 'n' values
1919
2020%% Pre-processing: Standardize Operators
21- % This step remains crucial. We replace all subtractions with "plus negative"
21+ % Replace all subtractions with "plus negative"
2222% to ensure the sign is correctly associated with its magnitude 'q'.
2323% Example: "A - B" becomes "A + -B"
2424no_space_str = erase(input_str , whitespacePattern );
8585% expression becomes zero.
8686singularity = @(x , a , n ) (n >= 0 ) .* (x > a ) .* (x - a ).^n ;
8787
88- %% 2. Programmatic and Automated Calculation
88+ %% Programmatic and Automated Calculation
8989% This advanced version replaces the switch-case with a universal mathematical
9090% rule for singularity function integration, making the code more concise
9191% and scalable.
9696 a = offsets(i );
9797 n = exponents(i );
9898
99- % --- Contribuição para a CURVA de Carregamento (apenas n >= 0) ---
100- if n >= 0
101- q_plot = q_plot + q * singularity(x , a , n );
102- end
103-
104- % --- Universal Integration Rules ---
99+ % Universal Integration Rules
105100
106101 % Contribution to Shear (V)
107102 v_exp = n + 1 ;
114109 M = M + (q / m_den ) * singularity(x , a , m_exp );
115110end
116111
117- % --- Bloco de Plotagem Aprimorado ---
118112
119- % Invertendo a convenção de sinais (conforme seu código)
113+
114+ %% Enhanced Plotting Block
115+
116+ % Inverting the sign convention (as per your code)
120117V = - V ;
121118M = - M ;
122119
123- % Cria o vetor para a linha do eixo zero
120+ nan_index = find(isnan(V ));
121+ V(nan_index ) = V(nan_index - 1 );
122+
123+ V(end ) = 0 ; M(end ) = 0 ;
124+
125+ % dyna_padder = @(in_vector) max([abs(min(in_vector)), max(in_vector)]);
126+
127+ % Creates the vector for the zero-axis line
124128y = zeros(size(x ));
125129
126130figure(' Name' , ' Beam Analysis Diagrams' );
127131
128- % --- Loading Diagram (q) ---
129- subplot(3 , 1 , 1 );
130- % Plota a curva das cargas distribuídas
131- plot(x , q_plot , ' b' , ' LineWidth' , 1.5 );
132- hold on ;
133- plot(x , y , ' k--' );
134- grid on ;
135- title(' Loading Diagram' );
136- ylabel(' Load (N)' );
137- fill([x , fliplr(x )], [q_plot , fliplr(y )], ' b' , ' FaceAlpha' , 0.3 , ' EdgeColor' , ' none' );
138- % Agora, adiciona as forças e momentos concentrados
139- for i = 1 : length(magnitudes )
140- q = magnitudes(i );
141- a = offsets(i );
142- n = exponents(i );
143-
144- if n == - 1 % Força Pontual
145- if q > 0 % Seta para cima
146- plot([a , a ], [-0.1 * max(abs(ylim )), 0 ], ' b' , ' LineWidth' , 1.5 );
147- plot(a , - 0.1 * max(abs(ylim )), ' b^' , ' MarkerFaceColor' , ' b' , ' MarkerSize' , 8 );
148- else % Seta para baixo
149- plot([a , a ], [0.1 * max(abs(ylim )), 0 ], ' r' , ' LineWidth' , 1.5 );
150- plot(a , 0.1 * max(abs(ylim )), ' rv' , ' MarkerFaceColor' , ' r' , ' MarkerSize' , 8 );
151- end
152- text(a , - 8 , sprintf(' %.1f ' , q ), ' HorizontalAlignment' , ' center' );
153- elseif n == - 2 % Momento Concentrado
154- if q > 0 % Anti-horário
155- text(a , 0.1 * max(abs(ylim )), ' \circlearrowleft' , ' Color' , ' g' , ' FontSize' , 16 , ' HorizontalAlignment' , ' center' , ' FontWeight' , ' bold' , ' Interpreter' , ' latex' );
156- else % Horário
157- text(a , 0.1 * max(abs(ylim )), ' \circlearrowright' , ' Color' , ' g' , ' FontSize' , 16 , ' HorizontalAlignment' , ' center' , ' FontWeight' , ' bold' , ' Interpreter' , ' latex' );
158- end
159- text(a , - 0.2 * max(abs(ylim )), sprintf(' M=%.1f ' , q ), ' HorizontalAlignment' , ' center' );
160- end
161- end
162- hold off ;
163-
164132% Shear Force Diagram
165- subplot(3 , 1 , 2 );
166- plot(x , V , ' m ' , ' LineWidth' , 1.5 );
133+ subplot(2 , 1 , 1 );
134+ plot(x , V , ' LineWidth' , 1.5 , ' Color ' , ' b ' );
167135hold on ;
168136plot(x , y , ' k--' );
169137grid on ;
138+ box on ;
170139title(' Shear Force Diagram' );
171140ylabel(' Shear Force (N)' );
172141xlabel(' Position (x)' );
173- fill([x , fliplr(x )], [V , fliplr(y )], ' m' , ' FaceAlpha' , 0.3 , ' EdgeColor' , ' none' );
142+ fill([x , fliplr(x )], [V , fliplr(y )], ' b' , ' FaceAlpha' , 0.3 , ' EdgeColor' , ' none' );
143+ xlim([min(x ) max(x )]);
144+ ylim([min(V ) max(V )]);
174145hold off ;
175146
176147% Bending Moment Diagram
177- subplot(3 , 1 , 3 );
178- plot(x , M , ' r ' , ' LineWidth' , 1.5 ); % Cor vermelha para diferenciar
148+ subplot(2 , 1 , 2 );
149+ plot(x , M , ' LineWidth' , 1.5 , ' Color ' , ' r ' ); % Red color to differentiate
179150hold on ;
180151plot(x , y , ' k--' );
181152grid on ;
153+ box on ;
182154title(' Bending Moment Diagram' );
183155ylabel(' Bending Moment (Nm)' );
184156xlabel(' Position (x)' );
185157fill([x , fliplr(x )], [M , fliplr(y )], ' r' , ' FaceAlpha' , 0.3 , ' EdgeColor' , ' none' );
158+ xlim([min(x ) max(x )]);
159+ ylim([min(M ) max(M )]);
186160hold off ;
0 commit comments