Is my code set up correctly? (Vectors)

I'm struggling with this and have no idea if my code is correct or where it's gone wrong.
Here's what the question wants:
The formula is:
where:
N = The concentration of solute at position x and time t; No = The initial concentration of solute at x = 0 D = The (so called) diffusion coefficient
I need to write a matlab program where x is a vector with values from 0 to 10. And then "compute a concentration vector N, given the following values for variables appearing in the Fick’s Law approximation, above, that are listed below:" t = 4.5; D = 3.0; and No = 19.0
Here's the code I wrote but I'm really at a loss with this.
x = 0:10;
t = 4.5;
D = 3.0;
No = 19;
for n = 0:10;
N = No * [1-2.*(x/2*sqrt(D*t*pi))]
end

Respuestas (1)

Star Strider
Star Strider el 29 de Sept. de 2018
It seems to be correct. However you do not need the loop, since the ‘N’ calculation is not a function of ‘n’.
So simply do:
x = 0:10;
t = 4.5;
D = 3.0;
No = 19;
N = No * (1-2.*(x/(2*sqrt(D*t*pi))))
And you need an extra set of parentheses around ‘(2*sqrt(D*t*pi))’.
Also, use parentheses rather than square brackets, since you are not defining a vector of specific elements.

Categorías

Más información sobre Get Started with MATLAB en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 29 de Sept. de 2018

Respondida:

el 29 de Sept. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by