Message Boards Message Boards

Can anyone please check my code and help me? about NDSolve and Plot

Posted 11 years ago

I cant get this code working no matter how much i change. Can anyone please check for me and help me?

In[50]:= var1 = graph1[input1];

In[76]:= 
soln3 = Simplify[
   Solve[{iout == (k*((vdd - vin - vt)*(vdd - 
              vo[t]) - ((vdd - vo[t])^2/2)) - (k/2*(vin - vt)^2)),
     vin == m*t}, iout, {vin}]];


During evaluation of In[76]:= Solve::ratnz: Solve was unable to solve the system with inexact coefficients. The answer was obtained by solving a corresponding exact system and numericizing the result. >>

In[77]:= stage2[t] = iout /. Part[Part[soln3, 1], 1];




In[75]:= soln4 = 
  NDSolve[{vo'[t] == stage2[t]/c0, vo[input1] == var1}, {vo[t]}, {t, 
    input1, vdd/m}];

During evaluation of In[75]:= NDSolve::ndinnt: Initial condition graph1[1.*10^-9] is not a number or a rectangular array of numbers. >>

In[78]:= graph2[t_] = vo[t] /. Part[Part[soln4, 1], 1];

During evaluation of In[78]:= ReplaceAll::reps: {(vo^[Prime])[t]==100000000000 (0.07 -4.*10^7 t-5.*10^15 t^2+(0.01 +1.*10^7 t) vo[t]-0.005 vo[t]^2)} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing. >>

In[79]:= root2 = FindRoot[temp*m == graph2[temp] - vt {temp, input1}];

During evaluation of In[79]:= FindRoot::argmu: FindRoot called with 1 argument; 2 or more arguments are expected. >>

In[58]:= input2 = Part[Part[root2, 1], 2];


Plot[graph2[t], {t, input1, input2}, 
 PlotRange -> {{input1, input2}, All},
 PlotStyle -> Gray, Frame -> True, GridLines -> Automatic, 
 FrameTicks -> Automatic, AspectRatio -> 0.5, ImageSize -> {500, 250}]

During evaluation of In[126]:= ReplaceAll::reps: {(vo^[Prime])[temp]==100000000000 (0.07 -4.*10^7 temp-5.*10^15 temp^2+(0.01 +1.*10^7 temp) vo[temp]-0.005 vo[temp]^2),vo[1/1000000000]==graph1[1/1000000000]} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing. >>

During evaluation of In[126]:= Plot::prng: Value of option PlotRange -> {{1/1000000000,{-temp+(vo[temp]/. {(vo^[Prime])[temp]==100000000000 Plus[<<5>>],vo[1/1000000000]==graph1[1/1000000000]}),-(1/1000000000)+(vo[temp]/. {(vo^[Prime])[temp]==<<1>>,<<1>>})}},All} is not All, Full, Automatic, a positive machine number, or an appropriate list of range specifications. >>

During evaluation of In[126]:= ReplaceAll::reps: {(vo^[Prime])[temp]==1.*10^11 (0.07 -4.*10^7 temp-5.*10^15 temp^2+(0.01 +1.*10^7 temp) vo[temp]-0.005 vo[temp]^2),vo[1.*10^-9]==graph1[1.*10^-9]} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing. >>

During evaluation of In[126]:= ReplaceAll::reps: {(vo^[Prime])[temp]==1.*10^11 (0.07 -4.*10^7 temp-5.*10^15 temp^2+(0.01 +1.*10^7 temp) vo[temp]-0.005 vo[temp]^2),vo[1.*10^-9]==graph1[1.*10^-9]} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing. >>

During evaluation of In[126]:= General::stop: Further output of ReplaceAll::reps will be suppressed during this calculation. >>

During evaluation of In[126]:= Plot::plln: Limiting value {-temp+(vo[temp]/. {(vo^[Prime])[temp]==100000000000 (0.07 +Times[<<2>>]+Times[<<2>>]+Times[<<2>>]+Times[<<2>>]),vo[1/1000000000]==graph1[1/1000000000]}),-(1/1000000000)+(<<1>>)} in {graph2[t],input1,input2} is not a machine-sized real number. >>

Out[126]= Plot[graph2[t], {graph2[t], input1, input2}, 
 PlotRange -> {{input1, input2}, All}, PlotStyle -> Gray, 
 Frame -> True, GridLines -> Automatic, FrameTicks -> Automatic, 
 AspectRatio -> 0.5, ImageSize -> {500, 250}]
Attachments:
POSTED BY: nffddn
2 Replies

Dear nffddn,

it is quite difficult to debug your code. O think that there are many mistakes in it, to the extent that it is difficult to understand what you want to achieve.

Your code starts with this:

(* Graphics Options *)

aRatio = 6/11;              iSize = {11/2.54*72, 
  6/2.54*72};         (* 11 cm by 6 cm graph  *)
aRatio2 = 
 5/18;              iSize2 = {18*25, 5*25};
iSize3D = {11/2.54*72, 7/2.54*72};   view = {2, 1, 2};    view1 = {4, 
  1, 2};            (* 11 cm by 7 cm graph  *)

font1 = {"Courier", FontSize -> 10, FontWeight -> "Bold"};

pStyle1 = {RGBColor[0.8, 0, 0], PointSize[0.015], 
   Thickness[0.007]};  (* Default colour for single graph *)

pStyleB = {GrayLevel[0], PointSize[0.015], 
   Thickness[0.007]};     (* Black  *)

pStyle3D = {GrayLevel[0.8], PointSize[0.015], 
   Thickness[0.007]};      (* 3D Graphics  *) 

pStyle21 = {RGBColor[1, 0, 0], PointSize[0.015], 
   Thickness[0.007]};   (* Default colours for 2 graphs *)

pStyle22 = {RGBColor[0.3, 0, 0], PointSize[0.015], Thickness[0.007]};

pStyle31 = {RGBColor[1, 0, 0], PointSize[0.015], 
   Thickness[0.007]};   (* Default colours for 3 graphs *)

pStyle32 = {RGBColor[0, 0, 0], PointSize[0.015], Thickness[0.007]};
pStyle33 = {GrayLevel[0.5], PointSize[0.015], Thickness[0.007]};

pStyle31 = {RGBColor[0.8, 0, 0], PointSize[0.015], 
   Thickness[0.007]};  (* Alt. Default colours for 3 graphs *)

pStyle32 = {RGBColor[0.1, 0, 0.4], PointSize[0.015], Thickness[0.007]};
pStyle33 = {GrayLevel[0.5], PointSize[0.015], Thickness[0.007]};

pStyle61 = {RGBColor[0.5, 0.5, 0], PointSize[0.02], 
   Thickness[0.007]};  
pStyle62 = {RGBColor[0.3, 0.7, 0], PointSize[0.02], 
   Thickness[0.007]};  
pStyle63 = {RGBColor[1., 0, 0], PointSize[0.02], Thickness[0.007]}; 
pStyle64 = {GrayLevel[0.5], PointSize[0.02], Thickness[0.007]};  
pStyle65 = {RGBColor[0.1, 0, 0.4], PointSize[0.02], 
   Thickness[0.007]};   
pStyle66 = {RGBColor[0.2, 0, 0.7], PointSize[0.02], 
   Thickness[0.007]};  

pStyle71 = {RGBColor[0.8, 0.2, 0], PointSize[0.02], 
   Thickness[0.007]};  
pStyle72 = {RGBColor[1, 0, 0], PointSize[0.02], Thickness[0.007]};  
pStyle73 = {RGBColor[0.2, 0.8, 0], PointSize[0.02], 
   Thickness[0.007]};  
pStyle74 = {RGBColor[0.1, 1, 0], PointSize[0.02], Thickness[0.007]}; 
pStyle75 = {GrayLevel[0.5], PointSize[0.02], Thickness[0.007]};  
pStyle76 = {RGBColor[0.1, 0, 0.4], PointSize[0.02], 
   Thickness[0.007]};   
pStyle77 = {RGBColor[0.2, 0, 0.7], PointSize[0.02], 
   Thickness[0.007]};  


pStyleBlue = {RGBColor[0.2, 0, 0.4], PointSize[0.025], 
   Thickness[0.007]};       (* Good Blue colour  *)

Off[General::spell1]

which runs ok. It seems to make mostly definitions of colours etc and is unproblematic. By the way it is good practice to use the correct formatting in your posts- even though that might be a problem of the Community Editor in this case.

The next line of code is

input1 = vt/m;

That works as well. Then comes

N[1/1000000000]

That does not do anything in your program. You might want to clean out these lines to make the program more readable. Then come

soln = Simplify[
   NSolve[{ip == 
      k*((vdd - vin - vt)*(vdd - vo[t]) - (vdd - vo[t])^2/2), 
     vin == m*t}, {ip, vin}]];

stage1[t] = ip /. Part[Part[soln, 1] 1];

They run to some extent, but it is difficult to understand what they are meant to do. You use numerical integration, but have not given any values to the parameters. The next line produces the first error:

soln1 = NDSolve[{vo'[t] == stage1[t]/c0, vo[0] == vdd}, {vo[t]}, {t, 0, input1}];

This is because you want to integrate numerically (NDSolve) but have not given any value to input1, which is still only defined as vt/m. At this point it needs a numerical value.If you give a value to it, the program complains about the initial conditions, because vdd is not yet declared. If you give it a value you will find that c0 is not defined. Even if you define c0 it does not work because stage1[t] is not numerical. These kind of errors go all through the notebook. I wonder what happened. You have a long notebook and the first commands do not produce the correct outputs you need for the rest of the notebook. Have you somehow modified a long notebook? Have you not executed the first lines before proceeding to the next lines?

I think that it will be difficult to debug your code a this stage.

You might want to read a book like Wellin's "Programming with Mathematica: An Introduction".

Best wishes,

Marco

POSTED BY: Marco Thiel
Posted 11 years ago

NDSolve expects all variables to have been assigned constant numeric values unless they are the independent variable or the function of that independent variable that you are solving for. In your notebook vt/m has not been assigned any value and NDSolve fails.

Likewise for your second NDSolve where vdd/m, co, var1, input1 have not been assigned any numeric value.

stage1[t]= ..., stage2[t]= ... should probably have [t_] instead of [t]. You can check that by evaluating stage1[t] and then stage1[2] after you have defined stage1 and see the results with and without the _ included.

See if you can fix those items and update your code. Then we can start the next step of figuring this out.

POSTED BY: Bill Simpson
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract