Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have the following data that needs to be analyzed :

data = ToExpression@Import["http://pastebin.com/raw.php?i=8XKGYvSy", "Data"];

I have 6 sets of coordinates (including this one) that I can easily plot on the same graph with ListLinePlot. However, I need to determine the x-coordinate of each of the 6 curves that has a y-value of a specific number of my choosing, say, -3.

My goal is to do something like this with an intersection (using FindRoot between the line y=-3 and Interpolation[data]. When I run Interpolation[data], I get the following error message:

Interpolation::inder: The order-2 derivative of {-1.47,-7.0394} is not a tensor of rank 2 with dimensions 2. >>

I've seen similar uses of Interpolation for data sets much smaller than mine. Also, I'm importing my data from Excel if that makes a difference.

EDIT:

I have done what others pointed out and removed the redundant braces. However, some of my sets still turn up an error message when I use FindRoot.

data = First@ToExpression@Import["http://pastebin.com/raw.php?i=ayyGwmHw", "Data"][[1]]; f = Interpolation[data] FindRoot[f[x] = -3, {x,-.001}]

Produces the following error message:

Set::write: Tag InterpolatingFunction in InterpolatingFunction[{{-0.0316228,-0.0000316225}},{4,7,0,{100},{4},0,0,0,0,Automatic},{{-0.0316228,<<49>>,<<50>>}},{Developer`PackedArrayForm,{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,<<51>>},{-3.18065,-3.1091,-3.03726,-2.9653,-2.89326,-2.82049,-2.74795,-2.67462,-2.6016,-2.52775,-2.45388,-2.37942,-2.3048,-2.22943,-2.15383,-2.07749,-2.00068,-1.92324,-1.84519,-1.76636,-1.68673,-1.6063,-1.52493,-1.44259,-1.35918,-1.2746,-1.18877,-1.10161,-1.01302,-0.922938,-0.831354,-0.738193,-0.643498,-0.547431,-0.450204,-0.352232,-0.25411,-0.156647,-0.0608189,0.0322768,0.121594,0.206229,0.285555,0.359262,0.427319,0.489892,0.547309,0.599959,0.648252,0.692602,<<50>>}},{Automatic}][x] is Protected. >>

FindRoot::jsing: Encountered a singular Jacobian at the point {x} = {-0.001}. Try perturbing the initial point(s). >>

share|improve this question

closed as off-topic by Öskå, rasher, Michael E2, m_goldberg, Yves Klett Jul 2 at 6:57

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Öskå, rasher, Michael E2, m_goldberg, Yves Klett
If this question can be reworded to fit the rules in the help center, please edit the question.

    
your data has 3 levels. –  Algohi Jul 1 at 18:19
    
Concerning your update: you need f[x] == -3 not f[x] = -3 –  m_goldberg Jul 2 at 0:19
    
Thanks all fixed –  user16269 Jul 2 at 19:05

2 Answers 2

up vote 1 down vote accepted

Try this:

data = ToExpression@
   Import["http://pastebin.com/raw.php?i=8XKGYvSy", "Data"][[1]];
Interpolation[data]
share|improve this answer
    
Awesome! What did that do? (PS: I'm a beginner with mathematica) –  user16269 Jul 1 at 18:25
    
when you interpolate you need to have a list of two point sub lists. Some thing like this {{1,2},{3,4}}. in your case you had a redundant list in the outer level. some thing like this {{{1,2},{3,4}}}. –  Algohi Jul 1 at 18:31
    
So if I remove the outer curly braces then it will work? –  user16269 Jul 1 at 18:32
    
yes. that will work –  Algohi Jul 1 at 18:33
    
You're a life-saver! –  user16269 Jul 1 at 18:34

Just for completeness purposes:

data = First@ToExpression@Import["http://pastebin.com/raw.php?i=8XKGYvSy", "Data"];
f = Interpolation[data]
y[x_] := -3
Show@{Plot[{f[x], y[x]}, {x, Min[First /@ data], Max[First /@ data]}, PlotRange -> All], 
      ListPlot[data, AxesOrigin -> {0, 0}, PlotRange -> All, PlotStyle -> Red]}

Mathematica graphics

Where you can see that the intersection is around x = -0.2 so:

sol = FindRoot[f[x] == y[x], {x, -0.2}]

{x->-0.146545}

Visualize it:

Plot[{f[x], y[x]}, {x, Min[First /@ data], Max[First /@ data]}, PlotRange -> All, 
 Epilog -> {Red, PointSize@0.02, Point@{x /. sol, y[x /. sol]}}]

Mathematica graphics

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.