Group Abstract Group Abstract

Message Boards Message Boards

0
|
7.7K Views
|
8 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Need help to fix the syntax error in plotting

Posted 12 years ago

hi, I am working on a model. I tried to fit the model to the data. After fitting the model, I tried to plot the graph, but it is showing some error. Please help me to fix the problem. Attached the file for reference.

Thanks

Thanks, Jaydeep

Attachments:
POSTED BY: Jaydeep Yadav
8 Replies
Posted 12 years ago

I take your latest version of error.nb and evaluate that with no changes.

In part of your last step you wish to plot a function of Ca[te] and this does not work. So the first thing I do when a plot does not work is to look at a table of values of the function and see if this tells me why this does not work.

In[15]:= Table[Ca[te], {te, 0, 5}]

Out[15]= {Ca[0], Ca[1], Ca[2], Ca[3], Ca[4], Ca[5]}

Thus it appears that your Ca function may be undefined. That might explain why it will not plot.

Try a table of fit1[Ca[te], te]]

In[16]:= Table[fit1[Ca[te], te], {te, 0, 5}]

Out[16]= {Model3[0.00239865, 11.8628, 0.899403, 2.04314*10^-6, Ca[0], 0],
 Model3[0.00239865, 11.8628, 0.899403, 2.04314*10^-6, Ca[1], 1], 
 Model3[0.00239865, 11.8628, 0.899403, 2.04314*10^-6, Ca[2], 2], 
 Model3[0.00239865, 11.8628, 0.899403, 2.04314*10^-6, Ca[3], 3], 
 Model3[0.00239865, 11.8628, 0.899403, 2.04314*10^-6, Ca[4], 4], 
 Model3[0.00239865, 11.8628, 0.899403, 2.04314*10^-6, Ca[5], 5]}

and again it appears undefined.

Try a table of the expression you were trying to plot

In[17]:= Table[fit1[Ca[te], {Cb0, 0.1}], {te, 0, 5}]

Out[17]= {Model3[0.00239865, 11.8628, 0.899403, 2.04314*10^-6, Ca[0], {Cb0, 0.1}], 
 Model3[0.00239865, 11.8628, 0.899403, 2.04314*10^-6, Ca[1], {Cb0, 0.1}], 
 Model3[0.00239865, 11.8628, 0.899403, 2.04314*10^-6, Ca[2], {Cb0, 0.1}], 
 Model3[0.00239865, 11.8628, 0.899403, 2.04314*10^-6, Ca[3], {Cb0, 0.1}], 
 Model3[0.00239865, 11.8628, 0.899403, 2.04314*10^-6, Ca[4], {Cb0, 0.1}], 
 Model3[0.00239865, 11.8628, 0.899403, 2.04314*10^-6, Ca[5], {Cb0, 0.1}]}

and again it appears undefined.

Put the Evaluate back, which is not going to fix this.

In[18]:= Table[Evaluate[fit1[Ca[te], {Cb0, 0.1}], {te, 0, 5}]]

Out[18]= {Model3[0.00239865, 11.8628, 0.899403, 2.04314*10^-6, Ca[0], {Cb0, 0.1}], 
 Model3[0.00239865, 11.8628, 0.899403, 2.04314*10^-6, Ca[1], {Cb0, 0.1}], 
 Model3[0.00239865, 11.8628, 0.899403, 2.04314*10^-6, Ca[2], {Cb0, 0.1}], 
 Model3[0.00239865, 11.8628, 0.899403, 2.04314*10^-6, Ca[3], {Cb0, 0.1}], 
 Model3[0.00239865, 11.8628, 0.899403, 2.04314*10^-6, Ca[4], {Cb0, 0.1}], 
 Model3[0.00239865, 11.8628, 0.899403, 2.04314*10^-6, Ca[5], {Cb0, 0.1}]}

and again it appears undefined. But this gives a small red warning ^ which is a sign there is something very wrong with your code.

Look at all details of Cb0 for information

In[19]:= FullForm[Cb0]

Out[19]//FullForm= Cb0

Thus Cb0 appears completely undefined. Thus you are not able to get a graph of Ca[te]. Thus the problem is with your NonlinearModelFit or with your NDSolve.

Read the documentation for FittedModel. See there is an example showing how to use Normal to see information about the result of the fit.

In[20]:= Normal[fit1]

Out[20]= Model3[0.00239865, 11.8628, 0.899403, 2.04314*10^-6, Cb0, te]

See that you do not get back an expression which models your data. Thus it seems likely that your use of NonlinearModel is incorrect and has failed.

I do not believe I understand almost anything about your code. But it looks like you are not asking NonlinearModelFit to find Ca[t], it appears you are asking it to find Cb0. Perhaps Ca[t] is gone long before you are trying to plot it. Since it appears you are asking it to find Cb0 and even Cb0 has no value. From the documentation for FittedModel, if I were going to guess from the examples I see there I would think I might look at the value of fit1[2,3] and not something like fit1[Ca[te],{Cb0, 0.1}].

In[21]:= fit1[2, 3]

Out[21]= 95.5808

and

In[22]:= Table[fit1[2, i], {i, 0, 5}]

Out[22]= {0., 60.2507, 85.3232, 95.5808, 99.7467, 101.433}

but the first argument to fit1 is almost certainly not 2. I have no idea what that value should be. The second I might guess would be a time between 0 and 50 so try

In[23]:= Plot[fit1[2, i], {i, 0, 5}]

Out[23]= ...PlotRemoved...

and at least it shows a plot, but this plot is guaranteed to be incorrect because we do not know what Cb0 should be or what te should be or even what Ca should be.

Can you begin to imagine why this problem seems more and more hopeless? Because it doesn't seem like any substantial progress is being made, even after all the requests to "please fix this.". There just does not seem to be an understanding of how to use NonlinearModelFit in the way you are using it and be able to get a correct and useful answer. That appears to be the fundamental problem which has been unchanged from the very beginning, other than changing random parts of the code which did not seem to help.

I hope it works out for you. Do you know and can you program in FORTRAN? You might consider that.

POSTED BY: Bill Simpson
Posted 12 years ago
POSTED BY: Bill Simpson
Posted 12 years ago

I was unable to find any difference between the two. I also went through your previous comment where you showed the code for both the problems. But I was unable to find the difference. In case if you know the difference,please let me know that might be the reason why one of them is not working.

Thanks

POSTED BY: Jaydeep Yadav
Posted 12 years ago
POSTED BY: Bill Simpson
Posted 12 years ago

Hi, I did not get you? What are you trying to say? Are you trying to say that both the codes are wrong or there is no difference between the code?

Thanks

POSTED BY: Jaydeep Yadav
Posted 12 years ago
POSTED BY: Bill Simpson
Posted 12 years ago

HI, Thanks for your efforts. I am attaching the file, where I had used these functions, earlier. They had worked. But I am not able to find the mistake which I am doing in "error.nb" .

Thanks for the help

Attachments:
POSTED BY: Jaydeep Yadav
Posted 12 years ago
Attachments:
POSTED BY: Jaydeep Yadav
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard