Matlab hyperbolic PDE equation errors

조회 수: 1 (최근 30일)
Amit Kumar
Amit Kumar 2014년 5월 15일
댓글: Amit Kumar 2014년 5월 15일
Hello people,
I am trying to solve a hyperbolic PDE and as a kickstart, I am using a code from matlab documentation but changing few parameters. However I am getting errors, which I cannot resolve. Basically I am solving a wave equation as given in matlab documentation but changing parameters f (forcing term) and a. Here is code:
clear all;
clc;
close all;
[p,e,t]=initmesh('squareg');
x=p(1,:)';
y=p(2,:)';
u0=sin(x);
ut0=cos(y);
n=31;
tlist=linspace(0,5,31);
a=cos(y); %GETTING ERROR HERE
f=sin(x); %GETTING ERROR HERE ALSO
uu=hyperbolic(u0,ut0,tlist,'squareb3',p,e,t,1,a,f,1);
figure; set(gcf,'renderer','zbuffer');
delta=-1:0.1:1;
[uxy,tn,a2,a3]=tri2grid(p,t,uu(:,1),delta,delta);
gp=[tn;a2;a3];
newplot;
umax=max(max(uu));
umin=min(min(uu));
for i=1:n
pdeplot(p,e,t,'xydata',uu(:,i),'zdata',uu(:,i),'zstyle','continuous',...
'mesh','off','xygrid','on','gridparam',gp,'colorbar','off');
axis([-1 1 -1 1 umin umax]); caxis([umin umax]);
M(i)=getframe;
end
movie(M,1);
I am not getting where I am making mistake in writing f and possibly a. Can someone comment? Thanks in advance!

답변 (1개)

Bill Greene
Bill Greene 2014년 5월 15일
There are several ways to define PDE Toolbox coefficients that vary spatially. But, defining the value of the coefficient at every node point, as in the lines where you are getting errors, is not one of them.
One way to define simple coefficients like in your example is simply to replace your two lines with these:
a = 'cos(y)';
f = 'sin(x)';
Defining coefficients as a string expression is documented here:
For more complicated coefficients, it is usually more convenient to define them using a MATLAB function. That approach is documented here:
Bill
  댓글 수: 1
Amit Kumar
Amit Kumar 2014년 5월 15일
Thanks a lot for your reply. If I want to make a function file,
function [ f ] = coeffunf(x,y)
f=sin(x)+sin(y);
end
And change those 2 specific lines as,
a='cos(y)';
f=coeffunf(x,y);
line a is wrote as you said, but line for 'f' is missing something again. I am messing up here again. Can you comment where I am going wrong?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 PDE Solvers에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by