How to plot this code?

2 visualizaciones (últimos 30 días)
hosi
hosi el 10 de Jul. de 2023
Comentada: hosi el 10 de Jul. de 2023
Hey guys I've been trying to learn mathlab and I ended up writing this code the code below:
clc
close all;
clear
L=input("L= ");
Delta_a=input("Delta a= ");
W=input("W= ");
E=input("Modulus Yang= ");
I=input("I= ");
EI=E*I;
N=L/Delta_a;
n=0;
while n<N
a=n*Delta_a;
y1=(-W/(24*EI))*((a^4)-(4*L*(a^3)+(6*(L^2)*(a^2))));
Rd=((3*EI)/(L^3))*(y1);
tb1=(-W*(L^3))/(6*EI);
tb2=(Rd*(a^2))/(2*EI);
yb1=(-W*(L^4))/(8*EI);
yb2=((Rd*(a^3))/(3*EI))+((L-a)*tb2);
thetaB=tb1+tb2;
yB=yb1+yb2;
n=n+1;
if(n>N) end
fprintf('n= #%d\n', n);
fprintf('Reaction D= #%d\n', Rd);
fprintf('Shib= #%d\n', thetaB);
fprintf('Khamesh= #%d\n', yB);
end
So here is my question:
How can I plot yB on diffrent values of a?
My guess is to turn it into a matrix but I have no idea about how to that.

Respuesta aceptada

N A POORNA CHANDRA
N A POORNA CHANDRA el 10 de Jul. de 2023
hi hosi , here is the code to plot yB on diffrent values of a?
i have assumed few hard coded values instead of taking them as input
clc
close all;
clear
L = 10; % Length (assumed value)
Delta_a = 0.5; % Delta a (assumed value)
W = 100; % W (assumed value)
E = 2e11; % Modulus of elasticity (assumed value)
I = 0.001; % I (assumed value)
EI = E * I;
N = L / Delta_a;
n = 0;
a_values = [];
yB_values = [];
while n < N
a = n * Delta_a;
y1 = (-W / (24 * EI)) * (a^4 - 4 * L * (a^3) + 6 * (L^2) * (a^2));
Rd = (3 * EI / (L^3)) * y1;
tb1 = (-W * (L^3)) / (6 * EI);
tb2 = (Rd * (a^2)) / (2 * EI);
yb1 = (-W * (L^4)) / (8 * EI);
yb2 = ((Rd * (a^3)) / (3 * EI)) + ((L - a) * tb2);
thetaB = tb1 + tb2;
yB = yb1 + yb2;
a_values = [a_values, a];
yB_values = [yB_values, yB];
n = n + 1;
end
plot(a_values, yB_values)
xlabel('a')
ylabel('yB')
title('Plot of yB against a')
grid on
  1 comentario
hosi
hosi el 10 de Jul. de 2023
Your an angel dude! thanks a lot! <3

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by