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: 

Odd integer search

Solved!
Go to solution

I'm new to LabVIEW and am having difficulty with one of the problems from CH.2 of hands on introduction to LabVIEW.  The problem states:

 

The odd integers are given by 2i + 1, where i = 0, 1, 2 ...  Write a program that answers the following question: What is the smallest odd integer that is divisible by 3 and also, when cubed, yields a value greater than 4000?  Display the answer to this question in a front pannel Numeric Indicator.

 

I have my front and block diagram attached.  I believe I have the beginning and end parts of the code correct, I'm confused how to tackle the part where it must be odd and divisible by 3.  Any ideas?  Thank you.

0 Kudos
Message 1 of 14
(6,247 Views)
Solution
Accepted by topic author dagabeo7

An odd interger that is divisible by 3 is an odd multiple of 3, so replace your Q&R with a multiplication by 3, then test cube value of it. See how far you get.

Also make sure to wire the numeric indicator to the value going into the cubing, the value of [i] is not iteresting.

0 Kudos
Message 2 of 14
(6,236 Views)

Thank you that helped.  There was suggested icons such as the Q&R, Power of X, and And.  I'm still not sure how to incorporate the Q&R and And, but I'm sure i'll figure it out soon  

0 Kudos
Message 3 of 14
(6,096 Views)

@dagabeo7 wrote:

Thank you that helped.  There was suggested icons such as the Q&R, Power of X, and And.  I'm still not sure how to incorporate the Q&R and And, but I'm sure i'll figure it out soon  


Well, the use of Q&R would complicate the code and it simply leads to another algorithm. Do you really have to use it?

 

What you would do instead is inspect [i] directly (less effiicient, because there will be many more to inspect. No big deal for a computer, though!). At each iteration, divide [i] by 3 using Q&R and see if the remainder is zero. if it is, [i] is divisble by three. Now see if the number is odd (you know how to do that, right?), and if both are true do the cubeing and check the size of the result. etc.

 

You could also do a hybrid approach, multiplying [i] by 3 at each iteration and then checking if the result is odd by using Q&R (dividing by 2) and see if the R is nonzero., etc.

 

As an exercise, You should do all three approaches and see if you get the same result. Also see which one uses the fewest number of iterations to find the solution.

Message 4 of 14
(6,088 Views)

Hi,

 

What is the smallest odd integer that is divisible by 3 and also, when cubed, yields a value greater than 4000?

x = 3*n
x^3 > 4000
-> x > 4000^(1/3)
-> x > 15.9

multiples of 3 greater than 15.9: 18, 21, 24, …

You really need a tool to provide the answer? 😄

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 14
(6,073 Views)

GerdW wrote:
x = 3*n
x^3 > 4000
-> x > 4000^(1/3)
-> x > 15.9

multiples of 3 greater than 15.9: 18, 21, 24, …

What's that gibberish? I thought this is the LabVIEW forum! 😄

 

-> x > 15.9

... so the minus sign is greater than x which is greater than 15.9? No wonder I am a graphical programmer. 😮

 

I don't think this is an exercise in number theory, but an exercise in LabVIEW programming (while loop, some math, condition checking, loop termination). You also left out a step, because you still need to check which result is odd. 😉

 

(Just being silly of course....)

0 Kudos
Message 6 of 14
(6,060 Views)

It was just an exercise problem. I don't think the problem is necessarily asking for the best approach, rather its just asking to attack the problem using these icons.  Thank you for the help though.  The correct answer is 21, I augmented the code and got it to spit out 21.  

0 Kudos
Message 7 of 14
(6,013 Views)

@dagabeo7 wrote:

It was just an exercise problem. I don't think the problem is necessarily asking for the best approach, rather its just asking to attack the problem using these icons.  Thank you for the help though.  The correct answer is 21, I augmented the code and got it to spit out 21.  


Well, the original problem description in your first post makes no restrictions on the tools to be used. If the puzzle asks to solve the problem given exactly the tools on your original diagram, nothing more, nothing less, that's a different problem (and I don't think it is solvable!) and you should have mentioned it in your first post. 😄

 

Feel free to show us your code for comments and suggestions

 

 

0 Kudos
Message 8 of 14
(6,001 Views)

it's too obvious "INTEGER"
not a floating point precision with decimal places

and clearly said it is an "ODD INTEGER"

 

an ODD and an INTEGER

😛

0 Kudos
Message 9 of 14
(5,917 Views)

@dhumpsy wrote:

 an ODD and an INTEGER


Are you replying to any particular post or statement?

0 Kudos
Message 10 of 14
(5,881 Views)