I have noticed that my model converge to different solutions when I'm running it directly in comsol and saving it as .m file and running it through matlab. Have anybody else had this problem? Any ideas as to why this is happening?
I think Rafik Ouchene put it in right terms. I have also had similar problems when I was trying to numerically solve a system of ode/pde in matlab. The results seem to be different when I use a FORTRAN code employing a basic RK4 method for odes. The solvers in matlab use a slightly different method for robustness and not to forget that matlab solvers use a variable step size method in calculating the solution. I am not sure as to what's the mathematical form of your model is, but I think it pretty much boils down to what Rafik Ouchene mentioned in his answer!
I'm not running the same problem in comsol and matlab and then getting two different answers. I save my comsol model as a *.m file and run it from matlab prompt. (With comsol livelink for matlab) So essentially I'm running the same thing at two different interfaces. (at a comsol server in matlab case, and from comsol desktop in the other) I believe the core of the model is same as I'm running a comsol model in both cases and the solvers involved are the same. So I'm not sure what you suggest is happening in this case. But I'll check more to make sure.
I had this experience, when I was trying to solve Schrodinger equation for a shallow quantum well. For a deep well I did not notice that. I even noticed for some situation, pressing "Compute" button repeatedly (inside COMSOL interface) would gave me different Eigenvalues. I do not know why?
I guess it is necessary to get consult From COMSOL Company in this case.
I thought the problem occur due to some error in conversion from comsol to matlab. But you seem to get the problem inside the comsol as well. How did you overcome this problem? did you try changing the mesh or anything to see if the result is different?
In my case, in 1D problem, the potential of the quantum well will start with a guess and then it will evolve to the real shape of quantum well after several iteration. I notice that if I start with spatial guess I would have deep enough well to get good accuracy from COMSOL solution even with the inaccuracy in some eigen values at the beginning. However, the problem is still exist and I did send an email to the COMSOL support. Unfortunately, I did not receive any answer.
Since my original question post, I came across following observations while working on the models.
Both models converge to the same solution if I build the model in comsol, and save it without the option of "compact History". This convert every action carried out from the beginning of the model in to matlab code, thus code is much longer, and there are many redundant lines as well. But I have noticed that the configurations in the solvers are also different. (so may be the solver default options in comsol and comsol livelink to matlab are different? very unlikely to happen)
I still don't fully know why the models converge to different solutions, but could identify this specific instance where solutions converge to different solutions and how to avoid it. So though of sharing since topic might be of interest to you as well.
Hey Waranatha, Vahid. I am also facing the same problem with my model wherein I get multiple solution when I run the same model in COMSOL again and again. I tried lowering the convergence, to bring the initial values as close as possible but this does not help. Have you guys fixed your models yet and can you please help me with some advice on this?
First, I recommend you to use new version of COMSOL. Second, pay attention to the mesh size. Finally for Eigenvalue problems, it is very important to give COMSOL a good estimation of the first Eigenvalue. In my case, The problem was just about Eigenvalues but I did not notice any difference on computation results in other PDEs.