Info

此问题已关闭。 请重新打开它进行编辑或回答。

Does anyone know how to fix this?

1 次查看(过去 30 天)
Caylan Stark
Caylan Stark 2019-12-4
关闭: MATLAB Answer Bot 2021-8-20
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 个评论
Ridwan Alam
Ridwan Alam 2019-12-4
Can you please share the code using the 'code editor'?
Capture.PNG

回答(1 个)

Ridwan Alam
Ridwan Alam 2019-12-4
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.

此问题已关闭。

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by