Having all the codes in a single file

2 ビュー (過去 30 日間)
Pouyan Msgn
Pouyan Msgn 2021 年 3 月 28 日
コメント済み: Jan 2021 年 3 月 29 日
I saw an example of boundary value problems in the book Numerical Analysis by Sauer. We have the non-linear equation:
The discretized form of this equation :
My question is not about how we solve such a problem. I already have the solution in three files. Ie two functions and a regular matlab file to perform it. I also attached files.I tried to write everything in a single file and wanted to see if it is possible to execute the algorithm without having to write Matlab functions. I did not succeed. Can anyone correct my code?
clc
clear all
n=15;
a=0; b=1; ya=1; yb=4;
h=(b-a)/(n+1);
J=zeros(n,n); %Jacobian
w=zeros(n,1);
y=zeros(n,1);
y(1)=ya-(2+h^2)*w(1)+h^2*w(1)^2+w(2); %BV
y(n)=w(n-1)-(2+h^2)*w(n)+(h^2)*(w(n)^2)+yb; %BV
for i=2:n-1
y(i)=w(i-1)-(2+h^2)*w(i)+(h^2)*(w(i)^2)+w(i+1);
end
for i=1:n-1
J(i,i+1)=1;
J(i+1,i)=1;
end
%The Matrix
for i=1:n
J(i,i)=2*h^2*w(i)-2-h^2;
end
%The solution!
w=w-J\y;
Y=[1;w;4];
plot(x,Y)
grid on
This is the True solution! but I dont get this plot!
  3 件のコメント
Pouyan Msgn
Pouyan Msgn 2021 年 3 月 28 日
I dont get the correct plot with my own code
Jan
Jan 2021 年 3 月 29 日
I do not get any output from your code at all, because x is not defined in the command plot(x,Y).

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by