MATLAB Answers

0

Error function plot with two variables

Asked by JUNHO JANG on 12 Jun 2019
Latest activity Commented on by Star Strider
on 12 Jun 2019
Hello guys I have to plot c(x,t)=c0-(c0-cs)erf(x/(2(Dt)^1/2)) Boundary condition is t>0, when the x is infinite, c=0. the fick's 2nd law.

  0 Comments

Sign in to comment.

2 Answers

Answer by Star Strider
on 12 Jun 2019

You will need the meshgrid (link) or (ndgrid (linked to on that page)) functions, and the surf (link) (or mesh (linked to on that page)) functions. The erf (link) function will make that calculation easier.
Code it. If you have problems, post back here with your code, a complete description of the problem, and all the red text from your Command Window for any errors that your code throws.

  3 Comments

syms x t
fplot x t
Warning: fplot will not accept character vector or string inputs in a future release. Use fplot(@(x)x) instead.
Error using fplot (line 149)
Invalid parameter 't'.
grid on
fplot(2*10^(-5)*(1-erf(x/(2*(10^(-5)*t)))))
I already tried it.
But I couldn't handle this...
Torsten
on 12 Jun 2019
Did you look at the examples provided under
?
They are almost identical to what you are trying to do.
@Junho Jang —
You are not using the correct plotting function.
Try this:
fsurf(2E-5*(1-erf(x/(2E-5*t))))
@Torsten —
Thank you!

Sign in to comment.


Answer by Steven Lord
on 12 Jun 2019

The fplot function is not the right tool for this job. Its documentation states that when called with one symbolic input it "plots symbolic input f over the default interval [-5 5]."
If you scroll down to the bottom of the documentation page for fplot there are a few other related functions listed. Two of the functions listed there will allow you to plot your surface (fmesh or fsurf.) fsurf when called with one symbolic input "creates a surface plot of the symbolic expression f(x,y) over the default interval [-5 5] for x and y." That sounds like what you're trying to do.
Of course, all of fplot, fmesh, and fsurf are supported not just for symbolic inputs but can accept function handles. See the examples on the documentation page for the fsurf function in MATLAB and try to adapt them to your problem.

  0 Comments

Sign in to comment.