LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Simple Plotting not working

Solved!
Go to solution

Hi there!

I want to plot a Super Lorentzian function. It's shape is like that of a top-hat if you go to high enough powers. Problem is, I can't seem to plot it. I perform simple arithmetic to calculate the function and use the tics of a while loop with steps of 0.1 as my x-value.

 

However, when I hoop it up with a waveform chart or any plotting VI it goes nuts. It's max value is suppposed to be 1, but it displays values like 10^-59 if I define my step as 0.1. If I define it as just 1, it somewhat displays the function, but only displays it between two extremely large values.

 

The function is this:

A / (B + ((X-C)^n) + D

 

A/B defines the maximum value

X is ofcourse x, the input

C is horizontal transliteration

n is the power (I use 😎

D is vertical transliteration

 

In my case, it's max value is supposed to be 1. I know what it will look like, so I want to plot it between 0 and 4.

 

This is supposed to be something trivial, but yet I can't pull it off. How can I plot my function?

0 Kudos
Message 1 of 11
(3,071 Views)

plotting goes wrong again.png

And this is something I just can't understand: it asks me for a 1D array of a cluster with 2 elements, which I give, only to say that they are not the same.

You can't see it well, but what I did was I used the bundle function to bundle the time which I converted into an array and the output of my function. Then I used the 'build array' VI to create an array of these two and voila, an error.

 

If I remove the array for my time (the iteration count) it will 'work', that is to say, it won't display an error. It does display extremely high values for the result and extremely low values (10^-52) for the x. This can't be right. What am I doing wrong?

0 Kudos
Message 2 of 11
(3,052 Views)
Solution
Accepted by topic author Choisai

Hello,

 

It's going wrong with the implementation of your steps.

 

The x-values in the first 4 iterations in your code are going like this:

0,1

1,1

2,1

3,1

4,1

...

 

I don't think this is what you want to obtain.

 

Please replace the "addition" by amultiplication (see attachment).

Please note that it is also dangerous to only check for "x equal to 4".

A better (but still not the best) way would be to check for "x equal to or greater than 4".

Kind Regards,
Thierry C - CLA, CTA - Senior R&D Engineer (Former Support Engineer) - National Instruments
If someone helped you, let them know. Mark as solved and/or give a kudo. 😉
Message 3 of 11
(3,027 Views)

I just slapped myself in the face for it, because it's so logical.

Unfortunately, I came across another problem, one I couldn't understand. The iteration count starts at 0. So now it should go from 0 to 4 in steps of 0,01. Except, it doesn't. At least it doesn't show like it does.Superlorentz fixed partially.pngSuperlorentz fixed partially part 2.png

You can see in the second image the x values are a bit odd. At first I thought I could circumvent it if I coupled the 'y' data of the function with the iterations of the x data in an array, and then hookt that array up with the graph. That however didn't work out too well:

Super Lorentz goes wrong 1.pngSuper Lorentz goes wrong 2.png

 

Maybe it is now just pushing arrays of 2 elements (one x and one y) into the graph and then it directly plots it. So I tried putting the graph outside of the loop. That didn't work either.

 

Maybe it's something different, I thought. Maybe if I supply it as a cluster:

Super lorentz as cluster 1.pngSuper lorentz as cluster 2.png

You can see this isn't working out either.

It should look like this:

Super Lorentz as it should be.png

I am looking at the calculations the program makes, but they should be fine. Or are they? Am I overlooking again something very basic here? How can I plot it normal?

0 Kudos
Message 4 of 11
(3,014 Views)

Hey Choisai,


The Charts can't take random x values as you are providing.. Or let me put it this way, you can't specify the x values explicitely for the chart. You can specify the 'dt' and intial value though.. So for your application, you can try using an XY graph where you can build the X and Y values into a cluster (use bundle function) and then wire it to the XY graph and you will see the expected x axis values.


regards,
Nitzz

(Give Kudos To Good Answers, Mark it as a Solution If your Problem was Solved :smileywink:)

Message 5 of 11
(3,007 Views)

I tried that, but the XY graph can only take a 1D array of a cluster of 2 elements, as can be seen here:

Super Lorentz Labview doesn't accept.png

 

This could easily be solved by turning it into an array using the 'build array' function

Super Lorentz plotter works partially.png

 

However, running this gives me an empty graph. 

Labview Super Lorentz partially working.png

I tried using the 'max X plot', which should give the 'end value' for X, but that didn't work either.

Running it normally gives me nothing, neither does the 'run continuously' function.

 

If I look at the X-axis I don't see the numbers I am supposed to see. It is better than the extremely large numbers I previously had, but it's not right. Am I doing it right? Or again something horribly wrong?

 

Thank you for your support and help so far!

0 Kudos
Message 6 of 11
(2,999 Views)

Hey Choisai,

 

You are almost there.. 🙂 Bring the graph outside4  the while loop and build the data into an array inside the loop. Outside the loop take out the built array and bundle the two columns/rows into a cluster and pass it to the XY graph. Sorry that i missed to mention this in my previous post.. Check the attached vi to see an example

 

regards,
Nitz

(Give Kudos To Good Answers, Mark it as a Solution If your Problem was Solved :smileywink:)

Message 7 of 11
(2,993 Views)

I tried, but failed:

Super lorentz to array.png

 

Trying it without the 0 and 1 doesn't work either. What is going on?

0 Kudos
Message 8 of 11
(2,986 Views)

Hey Choisal,

 

I think you paid a little less attention on the vi I posted.:) I can see that you have missed to enable auto indexing on the arrays terminal connected to the while loop output. Right click the output node where the array is wired and select auto index option. Then you will see that the array coming out of the while loop will be a 2d array instead of 1D and you wont fail this time.. 🙂

 

regards,
Nitzz

(Give Kudos To Good Answers, Mark it as a Solution If your Problem was Solved :smileywink:)

Message 9 of 11
(2,977 Views)

Superlorentz plot fixed.pngSuccesfull Labview VI 2.png

 

And it works! Thank you so much. It works now and it does exactly what I want. Thank you!

 

0 Kudos
Message 10 of 11
(2,969 Views)