Message Boards Message Boards

0
|
4801 Views
|
2 Replies
|
2 Total Likes
View groups...
Share
Share this post:

What is wrong with that Import and ListPlot code?

Posted 10 years ago

Hi, I have a code to import data from txt file which is list of some numbers like below:

6.6451
7.5027
7.4628
5.7056
3.0588
...

Code:

SetDirectory["E:\\Studia\\Magisterskie\\Magisterka"];
dat = Import["DM.txt"];
i = 2;
While[i <= Length[dat], aa = Table[dat[[k]], {k, 1, i}];
  mean[i] = 1/Length[aa]*Sum[aa[[k]], {k, 1, Length[aa]}];
  var[i] = 
   1/(Length[aa] - 1)*Sum[(aa[[k]] - mean[i])^2, {k, 1, Length[aa]}];
  n5[i] = 1.96^2*var[i]/(mean[i]*0.05)^2; i++];

bbb = Table[{i, mean[i][[1]]}, {i, 2, Length[dat]}];
PL = ListPlot[bbb, Joined -> True];
ddd = Table[{i, var[i][[1]]}, {i, 2, Length[dat]}];
PL5 = ListPlot[ddd, Joined -> True];
eee = Table[{i, dat[[i]][[1]]}, {i, 1, Length[dat]}];
PL0 = ListPlot[eee, Joined -> False];

f = mean[Length[dat]];
g = mean[Length[dat]][[1]] + 1*Sqrt[var[Length[dat]][[1]]];
h = mean[Length[dat]][[1]] - 1*Sqrt[var[length[dat]][[1]]];
v = var[Length[dat]];
PL1 = Plot[f, {x, 1, Length[dat]}, PlotStyle -> Black];
PL2 = Plot[g, {x, 1, Length[dat]}, PlotStyle -> {Red, Dashed}];
PL3 = Plot[h, {x, 1, Length[dat]}, PlotStyle -> {Green, Dashed}];
PL4 = Plot[v, {x, 1, Length[dat]}, PlotStyle -> Black];

xy = Show[{PL, PL1}, AxesLabel -> {"Liczba próbek", "?rednia E [GPa]"}]
Export["xy.jpg", xy, ImageResolution -> 500];
xyz = Show[{PL0, PL1, PL2, PL3}, 
  AxesLabel -> {"Liczba próbek", "E [GPa]"}]
Export["xyz.jpg", xyz, ImageResolution -> 500];
xyzz = Show[{PL4, PL5}, 
  AxesLabel -> {"Liczba próbek", "wariancja E [GPa]"}]
Export["xyzz.jpg", xyzz, ImageResolution -> 500];
n = n5[Length[dat]];

i = 0;
new = {};
Label[begin]; i = i + 1; If[i <= Length[dat], Goto[further], 
 Goto[end]];
Label[further]; If[h <= dat[[i]][[1]] <= g, Goto[next], 
 Goto[begin]]; Label[next]; new = 
 Join[new, {dat[[i]][[1]]}]; Goto[begin]; Label[end];

PL00 = ListPlot[new];
ff = Mean[new];
PL11 = Plot[ff, {x, 1, Length[new]}, PlotStyle -> Black];
PL22 = Plot[g, {x, 1, Length[new]}, PlotStyle -> {Red, Dashed}];
PL33 = Plot[h, {x, 1, Length[new]}, PlotStyle -> {Green, Dashed}];
xyz1 = Show[{PL00, PL11, PL22, PL33}]

Print["?redni modu? Younga= ", f, " GPa"]
Print["Wariancja= ", v, " GPa"]
Print["Liczba próbek= ", n]

Print["?redni modu? Younga= ", Mean[new], " GPa"]
Print["Wariancja= ", Variance[new], " GPa"]
Print["Liczba próbek= ", 1.96^2*Variance[new]/(Mean[new]*0.05)^2]

I tried to execute that code but then there is an error:

ListPlot::argx: ListPlot called with 0 arguments; 1 argument is expected. >>
ListPlot::argx: ListPlot called with 0 arguments; 1 argument is expected. >>
ListPlot::argx: ListPlot called with 0 arguments; 1 argument is expected. >>

**And much more errors due to this 3. It's something with the creation of the tables from the file i think, but i don't know what. Should I edit txt file somehow or there is something in the code to be fixed - code is not originally mine and I am kind of green with Wolfram.**

Please help me :)

Attachments:
POSTED BY: Sial Surion
2 Replies
Posted 10 years ago

Compare this, line by line, character by character, with the original. Study each changed character using the documentation to try to understand why the change was made.

If I have made a change then compare the value calculated by the original method and the value calculated by the new method. Use FullForm[value] on each so that Mathematica will hide less about what the result actually is in each case. Use that to try to understand why the method used was changed.

And carefully check some of the results by hand to make sure the results are correct and that there are not more errors in this.

In Mathematica almost anything can be done at least twelve different ways. Some will be faster, some will be easier to understand.

Some parts of the notebook could be made simpler, but I have tried to make the smallest number of changes to get what I think you want.

It was very helpful that you provided both the notebook and the data file it was to use. That made it possible to test the changes to see they work.

Attachments:
POSTED BY: Bill Simpson

This is a significant amount of code to debug. You may want to begin by breaking down that code. This will help you find where it is broken.

Your error message mentions that ListPlot[new] failing. Most likely then, something is wrong with the value of new.

I would evaluate each section independently to see where the first error appears. If you are new to programming in Mathematica, you may want to take a look at the virtual book before trying to debug this.

Goto and Label both need to be in a Module to work (see the documentation for these functions which have an example). My understanding is that this wasn't required in an earlier version of Mathematica. I would suggest starting by refactoring the section with Goto and Label.

POSTED BY: Sean Clarke
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