I think my program is complete What happen to this line? u(i)=sin(pi

Click For Summary
SUMMARY

The discussion centers on a MATLAB program designed to compute values of a function using finite difference methods. The line in question, u(i)=sin(pi*x(i));, raises concerns due to potential errors in variable initialization and indexing. Key parameters include n=10, h=0.1, and lambda=alpha*k/(h^2). The program iteratively computes values of u and y for time steps, but issues arise from the handling of the x array, which is not explicitly defined in the provided code.

PREREQUISITES
  • Understanding of MATLAB programming and syntax
  • Familiarity with finite difference methods for numerical analysis
  • Knowledge of boundary value problems in differential equations
  • Basic concepts of numerical stability and convergence in simulations
NEXT STEPS
  • Review MATLAB array indexing and initialization techniques
  • Learn about finite difference methods for solving partial differential equations
  • Explore MATLAB's built-in functions for numerical simulations
  • Investigate debugging techniques in MATLAB to identify runtime errors
USEFUL FOR

This discussion is beneficial for students and professionals in computational mathematics, MATLAB programmers, and anyone involved in numerical simulations of differential equations.

iwan89
Messages
27
Reaction score
0

Homework Statement


I think my program is complete.. What happen to this line? u(i)=sin(pi*x(i)); ??


Homework Equations



n=10;
c1=0;
c2=0;
k= 0.0025;
L=1;
h=0.1;
alpha=1;
T=0.025;
n=L/h;m=T/k;
lambda =alpha*k/(h^2);
z=0:h:L;
disp('______________________________________________')
fprintf(' t x = ')
fprintf('%4.2f ',z)
fprintf('\n')
disp('____________________________________________ _')
fprintf('% 5.4f ',0)
% Compute the values of u at t=0
for i=1:n+1
u(i)=sin(pi*x(i));
fprintf('%10.6f ',u(i))
end
fprintf('\n')
% Compute the values of u t=jk, k=1,2,...,m
for j=1:m
t=j*k;
fprintf('% 5.4f ',t)
for i=1:n+1
if (i==1)
y(i)=c1;
elseif (i==n+1)
y(i)=c2;
else
y(i)=(1-2*lambda)*u(i)+lambda*(u(i+1)+u(i-1));
end;
fprintf('%10.6f ',y(i))
end;
fprintf('\n')
u=y;
end;

The Attempt at a Solution


There might be error somewhere. Please help me to locate it :(
 
Physics news on Phys.org
this is a MATLAB program
 

Similar threads

Replies
2
Views
2K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K