Matlab hyperbolic PDE equation errors

3 views (last 30 days)
Amit Kumar
Amit Kumar on 15 May 2014
Commented: Amit Kumar on 15 May 2014
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!

Answers (1)

Bill Greene
Bill Greene on 15 May 2014
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 Comment
Amit Kumar
Amit Kumar on 15 May 2014
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?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!