绘图功能时出错

时间:2011-12-04 19:27:21

标签: matlab

我有以下功能:

function solve_heat_equation(T,N_time,N_space,A,B)
delta_t=T/N_time; 
delta_x=1/N_space; 
rho=delta_t/delta_x^2;
phi=zeros(N_space+1,N_time+1);
phi(:,1)=initial_condition((0:N_space)*delta_x);
for j=1:N_time;
    for i=2:N_space;
    phi(i,j+1)=rho*(phi(i-1,j)+phi(i+1,j))+(1-2*rho)*phi(i,j);
    end;
    phi(1,j+1)= (-2*A*delta_x - 4*phi(2,j+1) + phi(3,j+1))/-3;
    phi(N_space+1,j+1)=(2*B*delta_x+4*phi(N_space,j+1)+phi(N_space-1,j+1))/3;
end;

作为参考,初始条件是:

function z=initial_condition(x);
z=0.5-abs(0.5-x);

以上功能完美无缺;但是,当我尝试使用followign函数绘制结果时,我得到一个错误。

  

???使用==>时出错solve_heat_equation输出参数太多。

     

==>中的错误check_solution_to_heat_equation at 46       phi = solve_heat_equation(T,N_time,N_space,A,B);

clear all;
hold on;
grid on;
N_time = 1000;
N_space = 50;
A = 1;
B =1;
delta_x=1/N_space; 
x_var=(0:N_space)*delta_x;

for T=[0.01,0.05,0.25,0.5];
    phi = solve_heat_equation(T,N_time,N_space, A, B);
    plot(x_var,phi);
end;

我不确定我做错了什么,任何帮助都会受到赞赏。感谢。

1 个答案:

答案 0 :(得分:1)

您正在尝试从函数中提取返回值,但在编写函数时尚未声明任何返回参数。

也许你打算写:

function phi = solve_heat_equation(T,N_time,N_space,A,B)
...