|
Hi everyone. I'm building an app that compares measured voltage values in a 3 phase electrical system. My goal is to be able to calculate the phase imbalance. I have three computed properties which each calculate the difference between phase pair A-B, B-C and A-C and return the value as a Double Now my next step is to take each of the calculated values and compare them between each other and choose the biggest value from that. What would be the best way to go about this? |
|
You could put them in an array and use the Something like this:
|
|
While returning the max difference is very useful (@rooster's response), I wondered if you actually needed to know which pair of wires produced the max difference. Also took a shot at showing how breaking your big problem into smaller, solveable problems might be a useful technique. Please add a post and let us know what you learned.
|
|
A big thanks to both of you. Obelix, I appreciate your reply, but to be honest it is a little bit too advanced for me at the moment so I could't quite figure it all out. I'll have to dig in more to the code you posted to try and understand it all... I was able to solve that problem... only to find out that I'm facing a new one. :) I now have a computed property that uses the biggest value and passes it onward into a another computed property that makes the imbalance calculation using all the values that are needed and that calculation is shown in a text view in the UI. I have a problem regarding this text view. It says 'nan' before the user has entered values into the previous textfields. How can I make the text view show blank before the calculated values is passed on to be shown on that view? |
|
Toni apologizes:
Hey! No problem. This is an example of taking a big engineering problem and breaking it down into smaller, solvable chunks. Sorry, if I pushed you into the deep end of the pool while you're still learning to swim! But when you have a moment to think about the problem, consider each part of your physical 3-phase schematic. You have three wires? What are the properties of those wires? ( You need to calculate the voltage difference between two different wires? I created a Anyway, you might see how I took a larger electrical problem and decomposed it into smaller and smaller parts. Each part is responsible for a subset of calculations. Keep coding! |
|
Toni found a bug!
This might be a great case for using an If you have values, you can perform a calculation. But what if you don't have all the required values? What do you want your user to see? In some cases, you might want to substitute a default input value, say zero. But what about the case where the input value IS zero? This is bad because now you don't know if there is no value, or the user actually wants zero. In othercases, you might want to display nothing. You're the programmer. This is your decision to make. You can use |
SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.