1d Diffusion (for a complete newbe)

2 views (last 30 days)
Stefan Schwab
Stefan Schwab on 22 Nov 2015
Commented: Stefan Schwab on 23 Nov 2015
Hello everyone, I am very sorry if this question is stupid but I am totally new to matlab and want to use the program to fit diffusion data with an error function. From my experiences I get values like that: x ... depth in cm y ... concentration in [atoms/cm³) What I have done so far was to import the data to Matlab by using the import data button. I have now the x values as doubles and the y values as doubles in the program. Now I tried to fit the values with the following formula:
y=(C-B)*erfc(X/sqrt(4*D*t))+B
C and D are unknown, B and t are constants (which I entered by number) Now I was trying to fit the data with the following expression:
....................
ft=fittype('(C-3,21694e18)*erfc(x/sqrt(4*D*225900))+3,21694e18', 'independent', 'x', 'dependent', 'y' );
fitresult=fit(x,y,ft);
plot(fitresult,x,y)
...................
This is all I wrote into the program, so probably I missed something very basic. Nevertheless I get an error message:
................
Error in Diffusionsfitting (line 1)
ft=fittype('(C-3,21694e18)*erfc(x/sqrt(4*D*225900))+3,21694e18', 'independent', 'x', 'dependent', 'y' );
Caused by:
Error using fittype/evaluate (line 102)
Error in fittype expression ==> (C-3,21694e18).*erfc(x./sqrt(4.*D.*225900))+3,21694e18
??? Error: Expression or statement is incorrect--possibly unbalanced (, {, or [.
...................
Can you probably tell me, what I am doing wrong? I know, I should spend more time on matlab since I am missing all the basics. But as I am not used to programming and with limited time during my Ph.D. it's gonna take very long and I would really need the results for my research. Thank you very much for you're help. BR, Stefan

Answers (1)

Geoff Hayes
Geoff Hayes on 22 Nov 2015
Stefan - I don't have the Curve Fitting Toolbox so I can't tell with certainty what may be the problem. But looking at expression to fittype
'(C-3,21694e18)*erfc(x/sqrt(4*D*225900))+3,21694e18'
you have two commas rather than periods for two of the numbers. Try replacing your expression with
'(C-3.21694e18)*erfc(x/sqrt(4*D*225900))+3.21694e18'
  5 Comments
Geoff Hayes
Geoff Hayes on 23 Nov 2015
Stefan - please attach your data as a file rather than copying and pasting it into a comment. Also, describe how you use this data within your code as it may not be clear to everyone what each value represents.
Stefan Schwab
Stefan Schwab on 23 Nov 2015
Ok. I'd like to fit the data (x,Y) to the formula described above. I want that matlab calculates the C and D value (fitting).

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!