Suggestions for my code

3 views (last 30 days)
David
David on 23 Apr 2011
Hi all,
I am new to matlab and I have some troubles with my code. I tried to search for some answers but failed. Could anyone give me some suggestions?
clear
[x t]=meshgrid(0:5*10^(-5):200*10^(-5), 0:10:400);
Cxt = 0.0;
for i=0:6,
Cxt = Cxt + (-1)^i*erfc((2*(i+1)*200*10^(-5)-x) / (2*sqrt(t*1.04*10^(-6)))) + (-1)^i*erfc((2*i*200*10^(-7) + x) / (2*sqrt(t*1.04*10^(-6))));
end
mesh(x, t, Cxt)
I just want to have a 3d plot of Cxt, which is a function of x and t. But I always got the warning of "Warning: Matrix is singular to working precision" and no graphic output.
Thanks for help!

Answers (1)

Matt Fig
Matt Fig on 23 Apr 2011
When doing element-by-element computations, use .* .^ and ./
clear
[x t]=meshgrid(0:5*10^(-5):200*10^(-5), 0:10:400);
Cxt = 0.0;
for i=0:6,
Cxt = Cxt + (-1)^i*erfc((2*(i+1)*200*10^(-5)-x) ./ (2*sqrt(t*1.04*10^(-6)))) + (-1)^i*erfc((2*i*200*10^(-7) + x) ./ (2*sqrt(t*1.04*10^(-6))));
end
mesh(x, t, Cxt)

Community Treasure Hunt

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

Start Hunting!