XXpoints solution of possion1D equation

%Compute XX points possion1D equation
%Use S = 0 as the boundary condition for two external nodes of the gird
%command is 'XX=101'eg.101 points possion1D equation
function [FindSolution_function]=Possion1D_equation(XX)  
%sparse matrixs of coefficients_L and right side hands_R
L = sparse(XX,XX);
L1 = full(L);
R = sparse(XX,1);
R1 = full(R);

%found coordinate_x
x = 0:10:(XX-1)*10%1行 101列z = size(x);x1 = x(1,1);x2 = x(1,2);x101 = x(1,101);

%found right hand side R1
for i = 1:1:XX
   if i==1
       R1(i,1) = 0;
   elseif i==XX
       R1(i,1) = 0;
   else
       R1(i,1) = 1;
   end
end

%found coefficient L1
L1(1,1) = 1;
L1(XX,XX) = 1;
for i=1:1:XX
    %first line = 0 except fai1 = 1
    if abs(i)>=2
        L1(1,i) = 0;
    end
    %last line = 0 except fai101 = 1
    if abs(i)<=XX-1
        L1(XX,i) = 0;
    end
    %from second line to one hundred line 
    if abs(i)>=2 & abs(i)<=XX-1
        L1(i,i-1) = 2./(x(1,i)-x(1,i-1))./(x(1,i+1)-x(1,i-1));
        L1(i,i) = (-2./(x(1,i)-x(1,i-1))-2./(x(1,i+1)-x(1,i)))./(x(1,i+1)-x(1,i-1));
        L1(i,i+1) = 2./(x(1,i+1)-x(1,i))./(x(1,i+1)-x(1,i-1));
    end
end

%compute S:S1 = L1\R1
S1 = L1\R1
%visualize result of unknowns
i = 0:1:XX-1
plot(i,S1,'k','LineWidth',3)
title('Result of XX points possion equatioin');                                                         
xlabel('Points')
ylabel('value of unknowns')

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值