[ 3 / biz / cgl / ck / diy / fa / ic / jp / lit / sci / vr / vt ] [ index / top / reports ] [ become a patron ] [ status ]
2023-11: Warosu is now out of extended maintenance.

/sci/ - Science & Math


View post   

File: 31 KB, 128x503, data.jpg [View same] [iqdb] [saucenao] [google]
3876420 No.3876420 [Reply] [Original]

Will someone who has matlab/mathematica and knows how to use it please turn my table of data into a good function that hugs the points closely?

Thanks!

>> No.3876425

polyfit?

>> No.3876450
File: 19 KB, 360x240, cutey_Emma_overlightening.jpg [View same] [iqdb] [saucenao] [google]
3876450

yes, if you give it my in this format

{{0.5,500},{1.5,300},...,}

>> No.3876473

actually, {500,300,...} is okay too, since the t values are equidistant anyway

>> No.3876535

>>3876450
ok gimme a second

>> No.3876551
File: 10 KB, 541x412, lol.png [View same] [iqdb] [saucenao] [google]
3876551

I have no idea what am I doing
lol

>> No.3876559
File: 142 KB, 800x776, I_have_no_idea_what_Im_doing_ASR.jpg [View same] [iqdb] [saucenao] [google]
3876559

If you guess the dependency, I can also plot it in terms of fancier functions (cos, exp,...)

>>3876551
pic related

>> No.3876560

I'm thinking it might come out as something like e^(x*sin(x))

data = {{.5,500},{1.5,300},{2.5,250},{3.5,350},{4.5,750},{5.5,2
125},{6.5,4250},{7.5,5750},{8.5,5950},{9.5,5250},{10.5,4625}
,{11.5,4600},{12.5,4575},{13.5,4625},{14.5,4875},{15.5,5375}
,{16.5,800},{17.5,6050},{18.5,4950},{19.5,3400},{20.5,2500}&
#44;{21.5,2050},{22.5,1500},{23.5,800}}

>> No.3876564

>>3876559
what's the dependency?

>> No.3876572
File: 9 KB, 522x403, lol2.png [View same] [iqdb] [saucenao] [google]
3876572

>>3876551
the previous one was with a=polyfit(t,f,6), this one is a=polyfit(t,f,9), the function is
y= -0.0000000*x^9 0.0000000*x^8 -0.0000001*x^7 0.0000008*x^6 -0.0000027*x^5 -0.0000540*x^4 0.0006441*x^3 -0.0023968*x^2 0.0030930*x - 0.0005842

I still don't know wtf I'm doing, sorry I'm a noob

>> No.3876626

>>3876572
can you give me a polyfit of like 20?

>> No.3876638
File: 9 KB, 518x390, lol3.png [View same] [iqdb] [saucenao] [google]
3876638

>>3876626
15 looks pretty decent

a =

1.0e+004 *

-0.0000 0.0000 -0.0000 0.0000 -0.0000 0.0000 0.0000 -0.0003 0.0056 -0.0527 0.3166 -1.2181 2.9130 -4.0328 2.7881 -0.6330

>> No.3876646

>>3876638
the equation is fucked up

>> No.3876642
File: 452 KB, 500x600, cutey_Emma_redsihuett.png [View same] [iqdb] [saucenao] [google]
3876642

I don't think polynomials are the way to go here..

-152804. + 684587. x - 1.15654*10^6 x^2 + 1.04413*10^6 x^3 -
580144. x^4 + 213048. x^5 - 53596.2 x^6 + 9334.78 x^7 -
1107.04 x^8 + 83.7446 x^9 - 3.21354 x^10 - 0.0227597 x^11 +
0.00643525 x^12 - 0.0000227827 x^13 - 0.0000117267 x^14 -
8.00023*10^-8 x^15 + 1.97693*10^-8 x^16 + 6.25029*10^-10 x^17 -
1.7082*10^-11 x^18 - 1.71052*10^-12 x^19 - 3.44445*10^-14 x^20 +
1.6515*10^-15 x^21 + 1.35133*10^-16 x^22 + 3.33608*10^-18 x^23 -
8.09411*10^-20 x^24 - 1.01125*10^-20 x^25 - 3.79335*10^-22 x^26 -
1.84856*10^-24 x^27 + 5.88784*10^-25 x^28 + 3.56077*10^-26 x^29 +
8.88215*10^-28 x^30 - 1.61968*10^-29 x^31 - 2.52185*10^-30 x^32 -
1.0662*10^-31 x^33 - 9.63131*10^-34 x^34 + 1.4795*10^-34 x^35 +
8.66418*10^-36 x^36 + 9.20515*10^-38 x^37 - 1.15471*10^-38 x^38 -
3.65626*10^-40 x^39 + 1.24362*10^-41 x^40

>> No.3876659

>>3876642
do you have a better suggestion? (not trying to sound sarcastic, I'm being legit, idk what to do other than polynomials)

>> No.3876670

>>3876659
try ma poly and tell me what you like/don't like

>> No.3876686

>>3876659
Without knowing in advance what the relationship between your values are, you'll basically be able to always create a perfect fit with a high-enough valued polynomial. Which means, basically, that you know nothing, because you can always make a polynomial of degree n-1 for n data points.

>> No.3876687 [DELETED] 

>>3876646
the first seven values aren't exactly 0, but they're really really small (I multiplied them by large numbers to check)

this is what I used, change the line where a=polyfit to another value to compare (everything else should remain the same)
t=[0.5,1.5,2.5,3.5,4.5,5.5,6.5,7.5,8.5,9.5,10.5,11.5&#44
;12.5,13.5,14.5,15.5,16.5,17.5,18.5,19.5,20.5,21.5,22.5];
f=[500,300,250,350,750,2125,4250,5750,5950,5250,4625,460
0,4575,4625,4875,5375,5800,6050,4950,3400,2500,2050,1500
];
hold on
a=polyfit(t,f,15);
lin=linspace(0.5,22.5,100);
values=zeros(1,100);
for i=1:100
for len=1:length(a)
derp=length(a)-len;
values(i)=values(i)+a(len)*lin(i)^(derp);
end
end
plot(t,f,'+')
plot(lin,values,'r')

>> No.3876696

>>3876646
the first seven values aren't exactly 0, but they're really really small (I multiplied them by large numbers to check)

this is what I used, change the line where a=polyfit to another value to compare (everything else should remain the same)

t=[0.5,1.5,2.5,3.5,4.5,5.5,6.5,7.5,8.5,9.5,10.5,11.5&#44
;12.5,13.5,14.5,15.5,16.5,17.5,18.5,19.5,20.5,21.5,22.5];
f=[500,300,250,350,750,2125,4250,5750,5950,5250,4625,460
0,4575,4625,4875,5375,5800,6050,4950,3400,2500,2050,1500
];
hold on
a=polyfit(t,f,15);
lin=linspace(0.5,22.5,100);
values=zeros(1,100);
for i=1:100
for len=1:length(a)
derp=length(a)-len;
values(i)=values(i)+a(len)*lin(i)^(derp);
end
end
plot(t,f,'+')
plot(lin,values,'r')

>> No.3876714

I'm trying to get a function for the weekday plot

http://ops.fhwa.dot.gov/wz/p2p/ca4prs/presentations/i5stockton/index.htm

>> No.3876755

>>3876670
40 is too long, give me a 20 degree polynomial please

>> No.3876766

>>3876755
>fitting 23 data points with a degree-20 polynomial
Enjoy your garbage.

>> No.3876768
File: 8 KB, 511x407, fail.png [View same] [iqdb] [saucenao] [google]
3876768

>>3876755
the 15 one isn't good enough?
>>3876638

for some reason when I try 20 it derps

>> No.3876778

guys idk what I'm doing honestly. I don't know what degree I want. What I just want is a curve that decently resembles what I posted in that traffic thing. The numbers aren't all that important, I just want something that has that M shape. (And is somewhat adherent to the numbers)

>> No.3876781

>>3876768
That shouldn't be surprising. That is what happens when you try to fit data with high-degree polynomials.

>> No.3876786

use least squares nigga

http://www.youtube.com/watch?v=osh80YCg_GM
if you don't know what least squares is

>> No.3876788

>>3876714
Since it's a periodic function, try a Fourier series.

>> No.3876791

>>3876768
a least squares solution won't act like that

>> No.3876796

>>3876788
how?
can someone with mathematica/matlab type in like 'regression fourier' or something? Please help me

>> No.3876800

>>3876791
Yes, it will, and it's almost certainly what he did.

>> No.3876802

>>3876796
don't use a fourier series

>> No.3876810

>>3876786
oh thanks, I'm the person making graphs in matlab and I haven't started college yet so those videos will be useful haha

>> No.3876809
File: 24 KB, 551x561, cutey_Emma_smufing.jpg [View same] [iqdb] [saucenao] [google]
3876809

here's your 20 degree function, but well...

500.242 - 61233.8 x + 179562. x^2 - 218274. x^3 + 147990. x^4 -
63242. x^5 + 18155.6 x^6 - 3623.96 x^7 + 510.135 x^8 - 50.3063 x^9 +
3.33438 x^10 - 0.128776 x^11 + 0.000912453 x^12 + 0.000173841 x^13 -
7.52846*10^-6 x^14 - 2.47591*10^-8 x^15 + 1.18199*10^-8 x^16 -
4.10956*10^-10 x^17 + 5.62661*10^-12 x^18 - 8.93562*10^-15 x^19 -
3.50806*10^-16 x^20

>> No.3876807

>>3876800
nope, least squares wouldn't hit each point exactly

>> No.3876820

>>3876796
Since you've got regularly spaced data points, just do a discrete Fourier transform and throw away all but the lowest frequency terms.

>> No.3876821

>>3876768
runge phenomenon. it means you are fitting a higher order polynomial to your data than what it is physically represented by. In fact, looking at the data, I'd say that a polynomial fit is a very poor choice for this. I'd try either a piecewise cubic spline, OR a sum of sine/cosine functions (discrete fourier transform).

>> No.3876828

>>3876807
Given that the degree of the polynomial is almost the same as the number of data points, it should hit every point almost exactly, which is exactly what it does in that graph.

>> No.3876840

1. How would I do a discrete fourier transform?
2. What would it's result be?

Someone's really going to have to basically do this for me because honestly I haven't done anything like this before.

>> No.3876854

There are 24 hours in a day; where's your 24th data point?

>> No.3876937

>>3876560
DUDE....{16.5,800}
thank you...

>> No.3877023
File: 56 KB, 856x688, Bild 1.png [View same] [iqdb] [saucenao] [google]
3877023

>>3876937
here I was pointing out that you were giving me the wronge data value for 16.5 btw.

this

13547.5 - 58041.3 x + 97804. x^2 - 88396.4 x^3 + 49119. x^4 -
18031.1 x^5 + 4556.16 x^6 - 810.494 x^7 + 102.257 x^8 -
9.04292 x^9 + 0.533334 x^10 - 0.0175767 x^11 + 1.42908*10^-6 x^12 +
0.0000271765 x^13 - 9.49705*10^-7 x^14 - 8.42775*10^-9 x^15 +
1.62021*10^-9 x^16 - 5.33486*10^-11 x^17 + 7.86975*10^-13 x^18 -
3.94554*10^-15 x^19 - 1.22507*10^-17 x^20

is your 20 degree polynomial for the corrected data, you see the errors in the pic

>> No.3877032

this is the most useless thing to do ever

>> No.3877046

What is the point of this data set?

>> No.3877560

>>3877032
it's kinda for a project, really hard to explain, but I need to basically model traffic flow and lane closures in a program.

and yeah sorry, {16.5, 5800}