Hi, does anyone have any idea on how to solve this problem. Thank you very much. Really hope that someone can answer my question. Thank you.
Find value of z of a surface plot when values of x and y are known.
2 views (last 30 days)
Show older comments
I have a dispersal model to be solved numerically using matlab. The codes are as below:
function dispersal(fdis,c1,c2,L,T,h,k,D)
%solve the dispersal model with Initial Condition u(x,0)=fdis(x)and Boundary Condition c(0,t)=c1 and c(L,t)=c2 using explicit finite-difference (forward-difference) method.
n=L/h; m=T/k;
lambda=(D^2)*(k/(h^2))
z=0:h:L;
for i=1:n+1
u(i)=feval(fdis,(i-1)*h);
gt(1,i)=u(i);
end
for j=1:m
t=j*k;
for i=1:n+1
if (i==1)
y(i)=c1;
elseif (i==n+1)
y(i)=c2;
else
y(i)=(1-2*lambda)*u(i)+lambda*(u(i+1)+u(i-1));
end;
gt(j+1,i)=y(i);
end;
u=y;
end
box on
x=0:h:L; y=0:k:T;
[X,Y]=meshgrid(x,y);
surf(X,Y,gt)
xlabel('x'); ylabel('t'); zlabel('u');
end
The codes produced a solution in terms of a table and a surface plot. Now, i want to find the values of u when i provide the values of x and t from the surface plot. How should i do that in matlab codes??
Thank you very much.
Regards,
3 Comments
Walter Roberson
on 19 Sep 2012
t does not appear in the surface plot. You calculate t=j*k but you never use it.
Answers (1)
Laura Proctor
on 19 Sep 2012
Here is the example given from the doc link above:
% Create a data set:
x = rand(100,1)*4-2;
y = rand(100,1)*4-2;
z = x.*exp(-x.^2-y.^2);
% Construct the interpolant:
F = TriScatteredInterp(x,y,z);
% Evaluate the interpolant at the locations (qx, qy).
% The corresponding value at these locations is qz .
ti = -2:.25:2;
[qx,qy] = meshgrid(ti,ti);
qz = F(qx,qy);
mesh(qx,qy,qz);
hold on;
plot3(x,y,z,'o');
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!