From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LabView Exercise Problems

Hello guys,

I'm new to NI LabVIEW and currently trying to get better. I'm doing some example problems and having more trouble than I thought. could you guys please help.

Exercise #1 Write a program that asks the user to enter a positive integer n, and calculates the sum of the integers 2 + 4 + 6 + … + 2n and show the results to the screen. Hints: please check the validity of the positive integer n, what if user input a negative number?

 

Exercise #2 Write a program to simulate an experiment of flipping a coin a number of times (for example 100 times), and show the number of times getting heads and tails respectively. You can use random numbers to simulate the experiment. If the random number is >0.5, you can assume it is one side (for example Head), otherwise is the other side (for example Tail).

0 Kudos
Message 1 of 11
(6,609 Views)

Congratulations on getting started with LabVIEW and posting your first message on the forums.

 

Are you looking for help?  Perhaps you want to put a question into your message.

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

The attached picture is what i have for problem 1. i dont think its right. as for problem 2, i have no idea how to start it.

0 Kudos
Message 3 of 11
(6,596 Views)

Hello guys, im trying to do the follow problem "Write a program that asks the user to enter a positive integer n, and calculates the sum of the integers 2 + 4 + 6 + … + 2n and show the results to the screen. Hints: please check the validity of the positive integer n, what if user input a negative number?" Im new to labview and i attached my work. Can anyone tell me if my program is correct if not can you tell me how to fix it. Or if theres a better way to do it.

0 Kudos
Message 4 of 11
(6,560 Views)

https://forums.ni.com/t5/LabVIEW/LabView-Exercise-Problems/td-p/3797434

 

Please don't spam the forums with multiple threads asking the same question.

0 Kudos
Message 5 of 11
(6,543 Views)

As others have posted, you will get more help if you have specific questions on where you are stuck, but I'll give you some tips - when working on a problem, (especially when starting out programming) sometimes it's helpful to break down the problem into much smaller problems. On number one, forget about the user entry, checking for a positive number etc. Just try and figure out the algorithm. If n=10, whats the result? How did you figure it out? Even take programming out of the equation - what is the expression that defines what you are looking to do? 

 

Once you have the expression/algorithm defined, then look at the tools you have available in LabVIEW to code up that algorithm. Turn it into a VI - it should have one input (n) and one output - the result. Try it out with a few different numbers, and calculate the result by hand to verify you have it correct. Once you're that far, post your results and I am sure someone can help you with the next steps on getting user input. 

Message 6 of 11
(6,556 Views)

Although it's true that problem one requires only a solution to a common arithmetic series (and the answer can be expressed simply, without just adding all of the numbers), it might be more instructive with LabVIEW's tools to go ahead and just add the numbers.

I'd suggest reading about the following items (there should be links available via the LabVIEW Basics at the top of the forum).

  • For loop (and its iteration terminal, 'i')
  • Indexing tunnels (this is a type of output tunnel from the For loop - and it's the default for some datatypes)
  • The basic functions available on the Array palette of the block diagram.

For the second problem, you'll probably also want to consider a For loop. The operations as described in the hint should give you a good starting point. Some options after that could be:

  • Count only the values the are of one type (heads/tails), and then calculate the other type by subtraction from N
  • Count both types individually (consider reading about Shift Registers and either a Case Structure or the Select function)

GCentral
0 Kudos
Message 7 of 11
(6,542 Views)

@kevinlee2018 wrote:

The attached picture is what i have for problem 1. i dont think its right. as for problem 2, i have no idea how to start it.


You're close. As you should calculate sum(2*i) for i=(0..2N) you know you only need to calculate N times (since the 1st loop is 0, you'll need N+1 loops). So N is the loop iteration input, and in the loop you simply need to add i*2. The Shift register is nice, far too few use that early on. What will your result be with those tweaks?
As for how to start it, Ctrl+R or the Arrow in the toolbar will run it once.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 8 of 11
(6,519 Views)

Exercise 1 involves "doing something N times".  That should make you think of a For loop, with N wired to "N", the number of times the loop runs.  It also is made to get you to think about how For loops work, in particular, what the "i" terminal does (and how it relates to the number of times the loop has run).  It might also get you to think about a data structure that has N elements (I hope you know to what I am referring) that the For loop is often used to process or create.

 

Have you looked at the functions/operators on the Numeric Palette?  Do you see one that might be used to Sum something?

 

The Exercise also asks about "ask the user to enter a positive integer N".  How would you do this?  What do you think would happen if you put in a negative number by mistake (or deliberately)?  If you are not sure, write a little routine and test it.  You might be surprised by the result (though if you really understood For loops, you might have predicted it ...).

 

Exercise 2 is equally simple, but introduces another Structure (which I'm sure you can guess -- in case you need a hint, look at the Structure Palette, or re-read this sentence).

 

Bob Schor

0 Kudos
Message 9 of 11
(6,471 Views)

exercise #1:solution

0 Kudos
Message 10 of 11
(4,982 Views)