Does anyone know how to fix this?
Infos
Cette question est clôturée. Rouvrir pour modifier ou répondre.
Afficher commentaires plus anciens
I'm using forward differencing to estimate a differential equation, but my estimation isn't accounting for my boundary value y(10)=0
%cleanup
clc
clear
clf
%variables and setup
q = -0.6
EI = 1900
L = 10
%Analytical Solution and plot
f = @(x) (q*x.*(L.^3-2*L*x.^2+x.^3))/(24*EI)
x_exact = linspace(0,L)
y_exact = f(x_exact)
figure(1)
hold on
plot(x_exact,y_exact)
%Numerical Solution and Plot
dx = input('Input delta x value: ')
N = (L/dx)+1
y(1) = 0
y(L+1) = 0
y(10) = 0
x(1) = 0
x(2) = dx
C = (q*dx^2)/(2*EI)
for (i=2:N-1)
x(i+1) = x(i) + dx
y(i+1) = C*(x(i)*(x(i)-L))+2*y(i)-y(i-1)
i = i+1
end
plot(x,y)
title('Deflection vs. Position')
xlabel('X')
ylabel('Deflection')
legend('Exact Solution', 'Forward Differencing','Location','NorthWest')
1 commentaire
Ridwan Alam
le 4 Déc 2019
Can you please share the code using the 'code editor'?

Réponses (1)
Ridwan Alam
le 4 Déc 2019
0 votes
y(10) referes to the 10th element of the array y; not necessarily the value of y when x=10 or the last array element. to assign the last element of y, you can use the length of y (N) to initialize: y(N)=0 or y(length(y_exact))=0;
is your increment of i [i = i+1] intentional inside the for loop? also, the for loop runs upto i=N-1, then y(i+1)=y(N)=whatever is calculated by your equation and it overwrites your initial assignment.
a forward differencing doesn't use the end boundary value in estimating.
Cette question est clôturée.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!