我和之前的讨论有同样的问题,
[这里]有人可以解释如何在 MATLAB 中使用 contourf 绘制这个总和吗?
但是,现在我还没有处理轮廓,因为我还有另外两个问题需要回答。
我被告知取 N = 50, phi1 = 300, phi2 = 400, 0<=x<=1 和 0<=y<=1,并让 x 和 y 成为 100 个等距点的向量,包括终点。
这是两个问题,
a) 在单个图中(图 1),绘制 phi(x,y=1)、phi(x,y=0.8)、phi(x,y=0.5) 和 phi(x,y=0.1)。确保轴被标记,并且曲线具有不同的颜色。
b) 在单独的图中(图 2),将 phi(x,y=1)、phi(x,y=0)、phi(x=0,y) 和 phi(x=1,y) 绘制为子图(即 4 个单独的子图)。确保所有内容都已标记,并且希腊字母 phi 显示在 yaxis 标签中。
我已经回答了问题 a),但是当我尝试回答问题 b 时,我得到了错误。帮助?
clear all
close all
clc
clear
N=50;
phi1=300;
phi2=400;
%Phix10
%Phix08
%Phix05
%Phix01
x=linspace(0,1,100);
y=linspace(0,1,100);
y=1;
for k=1:100
sum=0;
tot=0;
for n=1:N
sum= sum + (2/n*pi)*((phi2-phi1)*((cos(n*pi)-1))/(exp(n*pi)-exp(-n*pi)))*((1-exp(-n*pi))*exp(n*pi*y)+(exp(n*pi)-1)*exp(-n*pi*y))*sin(n*pi*x(k));
end
Phi10(k)=phi1 - sum;
end
y=.8;
for k=1:100
sum=0;
tot=0;
for n=1:N
sum= sum + (2/n*pi)*((phi2-phi1)*((cos(n*pi)-1))/(exp(n*pi)-exp(-n*pi)))*((1-exp(-n*pi))*exp(n*pi*y)+(exp(n*pi)-1)*exp(-n*pi*y))*sin(n*pi*x(k));
end
Phi08(k)=phi1 - sum;
end
y=.5;
for k=1:100
sum=0;
tot=0;
for n=1:N
sum=sum + (2/n*pi)*((phi2-phi1)*((cos(n*pi)-1))/(exp(n*pi)-exp(-n*pi)))*((1-exp(-n*pi))*exp(n*pi*y)+(exp(n*pi)-1)*exp(-n*pi*y))*sin(n*pi*x(k));
end
Phi05(k)=phi1 - sum;
end
y=.1;
for k=1:100
sum=0;
tot=0;
for n=1:N
sum=sum + (2/n*pi)*((phi2-phi1)*((cos(n*pi)-1))/(exp(n*pi)-exp(-n*pi)))*((1-exp(-n*pi))*exp(n*pi*y)+(exp(n*pi)-1)*exp(-n*pi*y))*sin(n*pi*x(k));
end
Phi01(k)=phi1 - sum;
end
figure(1);
plot(x,Phi10,'r');
hold on;
plot(x,Phi08,'g');
hold on;
plot(x,Phi05,'y');
hold on;
plot(x,Phi01);
hold on;
title('plotting 1');
xlabel('x');
ylabel('y');
%my answer for question b
y=1;
for k=1:100
sum=0;
tot=0;
for n=1:N
sum= sum + (2/n*pi)*((phi2-phi1)*((cos(n*pi)-1))/(exp(n*pi)-exp(-n*pi)))*((1-exp(-n*pi))*exp(n*pi*y)+(exp(n*pi)-1)*exp(-n*pi*y))*sin(n*pi*x(k));
end
PhiB1(k)=phi1 - sum;
end
y=0;
for k=1:100
sum=0;
tot=0;
for n=1:N
sum = sum + (2/n*pi)*((phi2-phi1)*((cos(n*pi)-1))/(exp(n*pi)-exp(-n*pi)))*((1-exp(-n*pi))*exp(n*pi*y)+(exp(n*pi)-1)*exp(-n*pi*y))*sin(n*pi*x(k));
end
PhiB2(k)=phi1 - sum;
end
x=0;
for k=1:100
sum=0;
for n=1:N
% here's where i got the error
sum = sum + (2/n*pi)*((phi2-phi1)*((cos(n*pi)-1))/(exp(n*pi)-exp(-n*pi)))*((1-exp(-n*pi))*exp(n*pi*y(k))+(exp(n*pi)-1)*exp(-n*pi*y(k)))*sin(n*pi*x);
end
PhiB3(k)=phi1 - sum;
end
% x=1;
% for k=1:100
% sum=0;
% for n=1:N
% sum= sum + (2/n*pi)*((phi2-phi1)*((cos(n*pi)-1))/(exp(n*pi)-exp(-n*pi)))*((1-exp(-n*pi))*exp(n*pi*y)+(exp(n*pi)-1)*exp(-n*pi*y))*sin(n*pi*x);
% end
% PhiB4(k)=phi1 - sum;
% end
figure(2);
plot(x,PhiB1,'r');
hold on;
plot(x,PhiB2,'g');
hold on;
plot(x,PhiB3,'y');
hold on;
plot(x,PhiB4);
hold on;