To talk on Icrontic, just register!

It only takes 30 seconds.

Have an account? Sign in:

Forgot?
iamfromspacebaby
Getting settled in
iamfromspacebaby
8 Posts

Polynominal approximation, least squares fit & Bessel function

Hi all,

As Bessel functions are not supported in Max/MSP I have to do a polynominal approximation...

I'm using this webpage: //oak.ucc.nau.edu/jws8/dpgraph/drumheads.html as a resource.

The approximation is p(r) = rm (1 - r2) (a + b r2 + c r4 ) where 0 < r < 1. It is an approximation for Jm(km,n r).

Apparently I have to do a "least squares fit" for a, b and c.

Where m = 2, n = 1 and K = 5.135 the author of the webpage gets a = 3.03 and b = -2.45. However the values I get are alot smaller, they are: a = -0.042855 and b = 0.065353.

The code I have written is below:

function [p]=calcPolyApproximation(m,K)
%n = order, K=m'th zero of the n'th order bessel function
bessel = besselj(m,(0:.01:1).*K);
[p,s] = polyfit((0:.01:1).*K,bessel,3);
z = polyval(p,(0:0.01:1).*K);
figure;plot(bessel,'*');
hold on;plot(z,'g');

Any help would be appreciated,

Carl.

Btw. I am very new to Matlab so sensitive with me
shwaip
elaborate bot
shwaip
5,731 Posts
expanding the polynomial:
p(r) = r^m (1 - r^2) (a + b*r^2 + c*r^4)
means you actually need a r^(m+2+4) term in your polyfit, and you're only using the first 3.
__________________ my photostream for ic photography challenge

Anyone who wants dropbox, please use my referral link
iamfromspacebaby
Getting settled in
iamfromspacebaby
8 Posts
expanding the polynomial:
p(r) = r^m (1 - r^2) (a + b*r^2 + c*r^4)
means you actually need a r^(m+2+4) term in your polyfit, and you're only using the first 3.
Ahh yes, but even if I change that I still get very small results? Any other ideas?
shwaip
elaborate bot
shwaip
5,731 Posts
you can simplify this a bunch if you're willing to assume that 'm' is even. If this is ok, you can change the polynomial you're fitting. Let me know if this is an acceptable assumption - I'll whip up some code quickly.
shwaip
elaborate bot
shwaip
5,731 Posts
actually, you don't need that assumption. I'll have something in a sec...
shwaip
elaborate bot
shwaip
5,731 Posts
First you say:

p(r) = rm (1 - r2) (a + b r2 + c r4 ) where 0 < r < 1.

but then you try to fit this bessel function:
bessel = besselj(m,(0:.01:1).*K);

which has r outside the range of 0,1.

I think this is probably part of the problem...
iamfromspacebaby
Getting settled in
iamfromspacebaby
8 Posts
First you say:

p(r) = rm (1 - r2) (a + b r2 + c r4 ) where 0 < r < 1.

but then you try to fit this bessel function:
bessel = besselj(m,(0:.01:1).*K);

which has r outside the range of 0,1.

I think this is probably part of the problem...
Thanks for the quick reply. Well I have included *K because in the formula it stated that K needs to be multipled by r... tbh I wasn't sure about that myself.
iamfromspacebaby
Getting settled in
iamfromspacebaby
8 Posts
Thanks for your help so far... I think it is better but not 100%, and can someone enlighten me on the -01 -03 etc and how to get rid of them?

function [p]=calcPolyApproximation(m,K)
%n = order, K=m'th zero of the n'th order bessel function
bessel = besselj(m,0:.01:1,K);
[p,s] = polyfit(0:.01:1,bessel,4);
z = polyval(p,0:.01:1);
figure;plot(bessel,'*');
hold on;plot(z,'g');
iamfromspacebaby
Getting settled in
iamfromspacebaby
8 Posts
Well, infact I dont think the above is using the K value.. damn.

If anyone else has more suggestions I'd appreciate it as I'm stumped.
Similar Threads
Thread Thread Starter Forum Replies Last Post
Are you sure my dv8000t is Not a dv8000t? ~*~ Miska ~*~ General Hardware 19 25 Nov 2006 2:30am
Ad-Aware crashes in registry deep scan...possible malware? Treadstone71 Resolved / Inactive 23 8 Mar 2006 12:58am

Go Back   Icrontic Forums > Tech: Software > General Software > Matlab Help
Jump to
This Thread Search this Thread
Search this Thread:

Advanced Search


Current time: 10:46pm (GMT)
Powered by vBulletin®
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Get Vanilla instead. Trust me.