LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Model description of Modified Bessel function kn

Solved!
Go to solution

Hello friend,

 

I'd like to use Modified Bessel function kn to make a nonlinear fitting. 

Does anyone know the Model description of Modified Bessel function kn?

I tried besselk(0,x), besselk(x,0), and bessel_k0(x) which I used in excel and originlab; however, labview shows "not a valid function". 

 

Thank you!

 

Best regards,

Wen

0 Kudos
Message 1 of 10
(1,356 Views)

Is this what you are looking for?

Modified Bessel Function of the Second Kind.png

It is on the Mathematics Palette, Elementary and Special Functions, Bessel Functions sub-Palette.  Note that you need the Full or Professional version of LabVIEW.

 

Bob Schor

Message 2 of 10
(1,293 Views)

Hello Bob,

Thank you so much for the help!

I found this Bessel VI but I'd like to merge this function to make a new equation, then fit my data.

For example, my fitting equation is y = a*(bessel_k0(x/b)+bessel_k0(x/c)), where a, b, and c are fitting parameters. I tried nonlinear fitting VI to input the equation but bessel_k0 is not a function there but a string only.  

Do you know any method to do this kind of data fitting with Labview?

Thank you again!

0 Kudos
Message 3 of 10
(1,277 Views)

In LabVIEW, "bessel_k0(x/b)" is coded this way:Bessel Kn(x,b).png

 

Does this help?  Sorry that I didn't understand your question properly when you first asked it.

 

Bob Schor

 

Message 4 of 10
(1,237 Views)

Dear Bob,

 

Thank you so much!

It helps me a lot. Now I can code the equation.

But it seems the fitting doesn't work.??

I attached a picture. x and y data examples are also there. I want to get the best-fit parameters.

 

Best regards,

Wen

 

Wen2022_0-1671759946669.png

 

 

0 Kudos
Message 5 of 10
(1,205 Views)

Please do not attach "pictures of code" (hard to read very tiny images, sometimes you don't "see everything"), but rather attach a "test VI" (the actual LabVIEW .vi file that you "tried and found it didn't work") so that someone (such as I) can simply open up LabVIEW and start trying to find out what's wrong with the code.

 

Bob Schor

0 Kudos
Message 6 of 10
(1,184 Views)

Hello Bob,

A test VI is attached here.

Thank you!

Wen

0 Kudos
Message 7 of 10
(1,177 Views)

Well, I was able to partly "see" the code in your picture, and can make some comments about the "broken wire".  If you read the Help for the Levenberg-Marquardt algorithm, you'll see that it requires a function in the "f(x,a)" input.

LM Help.png

 

The Help gives you a Template for creating this function, where X are your Array of input data (X), a is the Bessel "order" (0), and f(x,a) is the Bessel function you are fitting.

 

It has been a few decades since I used Levenberg-Marquardt, but my Forum colleague @altenbach is definitely "up-to-date" on this algorithm, especially the LabVIEW implementation, but I encourage you to use the Help, write the appropriate Fitting Function, and pass its reference (do you know how to get a reference to the function?) to the f(x,a) (the bold letters on the Help means this is a required) input to the L-M function.

 

Bob Schor

 

0 Kudos
Message 8 of 10
(1,173 Views)
Solution
Accepted by topic author Wen2022

Hi, Wen.

 

     I was busy replying to your previous post and didn't see (until now) that you posted your code.  Thanks, among other things, it tells me which version of LabVIEW you are using.  You definitely want to look at the Examples listed at the end of the Help.  Note that they involve a separate "Model" VI that takes as inputs your model parameters (a, b, and c) and a sample value (x) and outputs a*Kn(x/b)+c, the model output whose fit to the data you are trying to optimize.  Once you've made a VI with your Model (I strongly recommend making a VI Icon for this Model, if nothing else saying "Bessel K0"), you'll need to go to the Application Control Palette, drop a Static VI Reference (which will have a big Question Mark in it), right-click it and choose "Browse for Path" (you need to have saved your Model, "Bessel K0 Model.vi"), right-click again and choose "Strictly-Typed VI Reference" (which puts a red Star on your Static VI Reference, meaning that it will "carry the Input and Output Types of the VI in the wire).  When you're done, you should have something more like this (which I haven't tested, as I wouldn't be sure what I was looking at, and thought you should have the experience of "seeing it first") ...

Wen Bessel Fit.png

 

I'm attaching my Model Bessel K0 function as a "Snippet" (which means you can drag it to an empty Block Diagram and it will automagically become LabVIEW 2021 code).  Note I haven't wired two inputs and two outputs, largely because I haven't studied the LM Examples closely enough to understand what these are used for, nor how to use them -- I need to leave something for the Students out there ...

Wen Snippet.png

 Bob Schor

 

  

Message 9 of 10
(1,162 Views)

Hi Bob,

 

Thanks a million for your time and kind help!!!!!

It works.

 

Best,

Wen

0 Kudos
Message 10 of 10
(1,152 Views)