LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

square function plot

Solved!
Go to solution

I make a program which calculate the root and the extremum of an square function. This program should also make a plot based on the function on an XY graph and here I am stuck.How can I make a plot of this functio?If I change the parameters a,b,c of the square function the plot should change too.

Download All
0 Kudos
Message 1 of 17
(5,758 Views)

Hi Newcomer,

 

create a ramp of X values, apply your polynomial on them, create a XY plot:

check.png

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 17
(5,753 Views)

Since you are learning LabVIEW, which (by design and "name") is a Laboratory Virtual Instrument Engineering Workbench (look at the initials), this might be a good time to explain (some of) the distinctions between a Chart and an XY Graph.  A significant amount of data acquired by LabVIEW comes from instruments, almost always consisting of equally-spaced time samples of data.  The X (= time) coordinate has equal increments, so you basically "know" it (you exactly know it if you know the starting time, called "t0" and the time step, called "dt").  Thus for a Chart, you only need the data, i.e. one array.

 

A Graph, on the other hand, allows you to plot X-Y pairs, where the X values need not be equally spaced, nor do they need to be in any order.  The "down side" is you need to compute both X and Y.

 

Your assignment appears to be to generate an XY Graph, so you need to generate an array of X values, plug them into the formula Y = f(X), and calculate the Y coordinate.  Under many circumstances, you say something like "I'd like to generate 100 points for X, covering the range 0 .. 10, and use this to plot Y = f(X)".  A simple For Loop, N = 101 (why not 100?), X = i/10 (i = loop index), Y = f(X) brought out through an indexing tunnel to make a Y array, and connected to a Chart, may be the way to go.  You may need to play with the X Scale (it will probably say 0 .. 100, but it's easy to make it say 0 .. 10).

 

Enjoy learning LabVIEW, and learning about LabVIEW.

 

Bob Schor

Message 3 of 17
(5,736 Views)

Thnaks for the fast reply :).

Another question How can I show the whole plot on the XY graph not only part of it?

0 Kudos
Message 4 of 17
(5,735 Views)

Here are a few screenshots I made

Download All
0 Kudos
Message 5 of 17
(5,732 Views)
Solution
Accepted by topic author NewcomerLabview

Hi New,

 

How can I show the whole plot on the XY graph not only part of it?

It shows the whole plot. As you defined it in your block diagram!

 

To learn about functions, you never used before, you should read the LabVIEW help about them.

Did you read the help for the Ramp function?

And why do you create that polynomial array with each iteration again? Wouldn't it be sufficient to do that just once before the loop?

And what about using AutoCleanup?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 6 of 17
(5,723 Views)

Thank you very much for your advise.

0 Kudos
Message 7 of 17
(5,707 Views)

On a side note, the polynomial evaluation function accepts arrays, so you don't need the FOR loop at all. I also typically use complex arrays for xy graphs.

 

Your front panel arrangement is such that the coefficients could easily be made into an array control, dramatically simplifying the diagram (1 terminal instead of three!)

 

Here's what I would do:

 

Xypoly.png

Message 8 of 17
(5,701 Views)

I would also use the caption to label elements for the array control. Here's how it could look like.

 

Xypoly.png

 

Note that this code is now fully scalable. For example if you want a linear or fourth order evaluation, all you need to do is change the size of the coefficient array! No other changes in code needed.

 

 

0 Kudos
Message 9 of 17
(5,696 Views)

OK, I was now looking at your original code and I think you can get away with <20% of the current code (which also seems to contain some glaring errors such as unwired tunnel outputs). It is also a really bad idea to set the array index of array indicators to "4", especially if the displayed container size is only four. This is not a "size" input! but simply determines which element (by index) is shown on top in the array container.

 

All you need is an array of coefficients in a shift register and a few subVIs that calculate the desired parameters from these coefficients and updates the indicators. Done right, the various calculations would fit inside the event frames. There is no need to keep the results in shift registers.

0 Kudos
Message 10 of 17
(5,692 Views)