• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 11:38
CEST 17:38
KST 00:38
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
Code S Season 1 - RO8 Preview4[ASL21] Ro8 Preview Pt2: Progenitors8Code S Season 1 - RO12 Group A: Rogue, Percival, Solar, Zoun13[ASL21] Ro8 Preview Pt1: Inheritors16[ASL21] Ro16 Preview Pt2: All Star10
Community News
Maestros of The Game 2 announcement and schedule !7Weekly Cups (April 27-May 4): Clem takes triple0RSL Revival: Season 5 - Qualifiers and Main Event12Code S Season 1 (2026) - RO12 Results12026 GSL Season 1 Qualifiers25
StarCraft 2
General
Code S Season 1 - RO8 Preview Behind the Blue - Team Liquid History Book Weekly Cups (April 27-May 4): Clem takes triple Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool Code S Season 1 (2026) - RO12 Results
Tourneys
Maestros of The Game 2 announcement and schedule ! GSL Code S Season 1 (2026) Sea Duckling Open (Global, Bronze-Diamond) RSL Revival: Season 5 - Qualifiers and Main Event Sparkling Tuna Cup - Weekly Open Tournament
Strategy
Custom Maps
[D]RTS in all its shapes and glory <3 [A] Nemrods 1/4 players
External Content
Mutation # 524 Death and Taxes The PondCast: SC2 News & Results Mutation # 523 Firewall Mutation # 522 Flip My Base
Brood War
General
Do we have a pimpest plays list? Why there arent any 256x256 pro maps? BGH Auto Balance -> http://bghmmr.eu/ (Spoiler) Asl ro8 D winner interview BW General Discussion
Tourneys
Escore Tournament StarCraft Season 2 [ASL21] Ro8 Day 4 Small VOD Thread 2.0 [BSL22] RO16 Group Stage - 02 - 10 May
Strategy
Simple Questions, Simple Answers Fighting Spirit mining rates What's the deal with APM & what's its true value Any training maps people recommend?
Other Games
General Games
Stormgate/Frost Giant Megathread Path of Exile Nintendo Switch Thread OutLive 25 (RTS Game) Dawn of War IV
Dota 2
The Story of Wings Gaming
League of Legends
G2 just beat GenG in First stand
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Vanilla Mini Mafia Mafia Game Mode Feedback/Ideas TL Mafia Community Thread Five o'clock TL Mafia
Community
General
European Politico-economics QA Mega-thread The Letting Off Steam Thread US Politics Mega-thread Canadian Politics Mega-thread Russo-Ukrainian War Thread
Fan Clubs
The IdrA Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece [Req][Books] Good Fantasy/SciFi books
Sports
2024 - 2026 Football Thread McBoner: A hockey love story Formula 1 Discussion
World Cup 2022
Tech Support
streaming software Strange computer issues (software) [G] How to Block Livestream Ads
TL Community
The Automated Ban List
Blogs
How EEG Data Can Predict Gam…
TrAiDoS
ramps on octagon
StaticNine
Funny Nicknames
LUCKY_NOOB
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1702 users

The Big Programming Thread - Page 171

Forum Index > General Forum
Post a Reply
Prev 1 169 170 171 172 173 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
lannisport
Profile Joined February 2012
878 Posts
October 02 2012 07:04 GMT
#3401
On October 02 2012 15:29 lannisport wrote:
I don't know if any of you guys are familiar with wordpress but I'm trying to use it as a content management system for a website. So my goal is this... To have a "template" with a header and footer in it, and to use wordpress to insert the content of the page inbetween those two. In HTML. It seems simple but I can't figure out how to do this.

Anyone have any suggestions? I just wanna insert plain HTML into wordpress to make the content of a page...

+ Show Spoiler +
<?php /*Template Name:default */ ?>
<?php get_header(); ?> <!-- This gets the header -->

<!-- The container is styled in CSS, so in WordPress I can simply type in the rest of the divs. "div id="section1", "div id="quote" etc. -->
<div id ="container">

<!-- Start the Loop. This is the WP Loop that returns the content the I type in the wordpress box and puts it into the div class "entry" -->
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="entry">
<?php the_content(); ?>
</div>

<?php endwhile; else: ?>
<?php endif; ?>
</div>


<?php get_footer(); ?> <!-- This gets the footer -->


Neater version: http://pastie.org/4895074

Currently this script messes up the layout of the page, and even some of the images go missing. However, it's all one CSS file so I don't understand why the layout would mess up (missing images probably a simple path problem).


Well this is embarrassing... I was stuck on this for two hours but I tried removing the comments in the HTML (<-- -->) and it worked >.> I'm pretty sure that ran through the W3C validator just fine.
Alryk
Profile Blog Joined November 2011
United States2718 Posts
October 02 2012 21:51 GMT
#3402
Hey guys. I hope this doesn't infringe on the "posting a block of code and asking what's wrong' thing. I have a systems of equations that I'm trying to solve in matlab, (freshmen in electrical engineering) and it's returning funky stuff, and I'm not sure why. I talked to my T.A. (graduate student who does the class) and they couldn't figure out why it was wrong, and we spent ~ten minutes on it. The systems of equations is right afaik, (checked a few times) and I just want to know why it is returning 1x1 sym for everything. Here is the equation:

+ Show Spoiler +
solve('-26 - 20*I1 - 35*(I1-I4) - 17*(I1-I3) == 0',...
'13 - 35*(I2-I3) - 82*(I2-I7) + 21 ==0',...
'-17*(I3-I1) - 28*(I3-I5) - 35*(I3-I6) - 34*(I3-I7) - 35*(I3-I2) - 13==0',...
'-35*(I4-I1) - 27*I4 + 6 - 28 - 15*(I4-I5) + 27 - 28*(I4-I5)==0',...
'-28*(I5-I4) - 27 - 15*(I5-I4) - 34*(I5-I6) - 28*(I5-I3)==0',...
'24 - 35*(I6-I3) - 34*(I6-I5) - 36*(I6-I7) - 36*(I6-I7)==0',...
'20 - 82*(I7-I2) - 34*(I7-I3) - 24 - 36*(I7-I6) - 36*(I7-I6) - 15*I7 ==0')

I1: [1x1 sym]
I2: [1x1 sym]
I3: [1x1 sym]
I4: [1x1 sym]
I5: [1x1 sym]
I6: [1x1 sym]
I7: [1x1 sym]

Sorry for choosing the worst variable possible to post in this font. Hopefully it makes sense, theoretically if you have matlab (or C++? Matlab uses that right?) you can just copy paste the above and it should work.
Team Liquid, IM, ViOlet!
lolmlg
Profile Joined November 2011
619 Posts
October 03 2012 01:27 GMT
#3403
On October 02 2012 12:29 white_horse wrote:
Show nested quote +
On September 30 2012 17:29 lolmlg wrote:
That explanation isn't really correct. The problem with the last version of his code was that the call to static_cast took place first. He wanted it to take place last. The line

static_cast<int>(1.07) * 100 / (0.10 * 100);

if it compiles (which it might not, if warnings are treated as errors) will yield the answer 10.0. In that example, all he would need to do in order to get the answer he wanted was surround the entire set of numeric operations with brackets, or use two static_cast calls to avoid the warning.

static_cast<int>(total * 100 / (0.10 * 100));
or
static_cast<int>(total) * 100 / static_cast<int>(0.10 * 100);

But then the question becomes, why bother with the multiplication? The operation can be reduced to the following:

static_cast<int>(total / 0.10);

Edit: Of course, this example didn't really apply to his program, because by the time he hit dimes, the amount of money should have been less than one, in which case the static_cast of total would have returned 0. So both the original line and the line with two static_cast calls would not have worked in his situation. The second line and the final one would be fine.


OK thank you so much that helped a lot. I have the program basically done now, and there is one problem left:
it works for every input except 19.96, 19.97, 19.98, and 19.99.

For example, 19.96 outputs everything right except at the very end, it doesn't output "One penny" on the screen when it needs to. And then 19.97 outputs only one penny at the end when it needs to output two. Do you know what is wrong with this? The assignment tells us to be careful about inputting 19.99 so it seems like this is a problem that we are supposed to run into.

Floating point values are not precise. It is very likely that the one cent you have left over by the penny step is actually represented by the value 0.00999593849 or something of that nature. I'll let you come up with a solution to that problem on your own.

On October 02 2012 15:53 dae wrote:
Show nested quote +
On September 30 2012 09:38 white_horse wrote:
Hey guys I'm working on this problem where the user inputs an amount of money between $0.00 and $19.99, and the program outputs the best way to calculate the change of that amount. So for example, if I put in "$9.94", then the program should output

One $5 bill
4 $1 bills
3 quarters
1 dime
1 nickel
4 pennies

I got this far

float total;
cout << "Input a dollar amount between 0.00 and 19.99 (inclusive): ";
cin >> total;

numTenDollar = static_cast<int>(total)*100 / (10*100);
numFiveDollar = static_cast<int>((total - numTenDollar))*100 / (5*100);
numOneDollar = static_cast<int>((total - numTenDollar - numFiveDollar))*100 / (1*100);

but the program is really weird when I run it and I think theres something wrong with the calculations. Can you guys help me out? Thanks.


Wouldn't this problem be very easy to solve by just using a series of while loops, one for each currency denomination?

eg:
while(currentAmount-10>=0)
{
numTenBills++;
currentAmount-=10;
}

You could even print the amounts as you go if you don't want to use a different variable for each denomination.

Let's put aside for a moment that this is an inefficient solution and really no simpler than the one he is already using. If he decided to switch, he would only run into similar floating point math problems.
waxypants
Profile Blog Joined September 2009
United States479 Posts
October 03 2012 05:06 GMT
#3404
On October 03 2012 10:27 lolmlg wrote:
Show nested quote +
On October 02 2012 12:29 white_horse wrote:
On September 30 2012 17:29 lolmlg wrote:
That explanation isn't really correct. The problem with the last version of his code was that the call to static_cast took place first. He wanted it to take place last. The line

static_cast<int>(1.07) * 100 / (0.10 * 100);

if it compiles (which it might not, if warnings are treated as errors) will yield the answer 10.0. In that example, all he would need to do in order to get the answer he wanted was surround the entire set of numeric operations with brackets, or use two static_cast calls to avoid the warning.

static_cast<int>(total * 100 / (0.10 * 100));
or
static_cast<int>(total) * 100 / static_cast<int>(0.10 * 100);

But then the question becomes, why bother with the multiplication? The operation can be reduced to the following:

static_cast<int>(total / 0.10);

Edit: Of course, this example didn't really apply to his program, because by the time he hit dimes, the amount of money should have been less than one, in which case the static_cast of total would have returned 0. So both the original line and the line with two static_cast calls would not have worked in his situation. The second line and the final one would be fine.


OK thank you so much that helped a lot. I have the program basically done now, and there is one problem left:
it works for every input except 19.96, 19.97, 19.98, and 19.99.

For example, 19.96 outputs everything right except at the very end, it doesn't output "One penny" on the screen when it needs to. And then 19.97 outputs only one penny at the end when it needs to output two. Do you know what is wrong with this? The assignment tells us to be careful about inputting 19.99 so it seems like this is a problem that we are supposed to run into.

Floating point values are not precise. It is very likely that the one cent you have left over by the penny step is actually represented by the value 0.00999593849 or something of that nature. I'll let you come up with a solution to that problem on your own.



Yes, this. I'm gonna go ahead and just spoil it a little bit. I would use fixed-point rather than floating point so that you can represent the values exactly. The only native fixed-point types you have are the integer types, so you will basically have to convert things to cents so that you are only dealing with integers. This will also involve writing your own function to parse user input since you will no longer be using floats, which shouldn't be too hard.
waxypants
Profile Blog Joined September 2009
United States479 Posts
October 03 2012 05:07 GMT
#3405
On October 02 2012 15:53 dae wrote:
Show nested quote +
On September 30 2012 09:38 white_horse wrote:
Hey guys I'm working on this problem where the user inputs an amount of money between $0.00 and $19.99, and the program outputs the best way to calculate the change of that amount. So for example, if I put in "$9.94", then the program should output

One $5 bill
4 $1 bills
3 quarters
1 dime
1 nickel
4 pennies

I got this far

float total;
cout << "Input a dollar amount between 0.00 and 19.99 (inclusive): ";
cin >> total;

numTenDollar = static_cast<int>(total)*100 / (10*100);
numFiveDollar = static_cast<int>((total - numTenDollar))*100 / (5*100);
numOneDollar = static_cast<int>((total - numTenDollar - numFiveDollar))*100 / (1*100);

but the program is really weird when I run it and I think theres something wrong with the calculations. Can you guys help me out? Thanks.


Wouldn't this problem be very easy to solve by just using a series of while loops, one for each currency denomination?

eg:
while(currentAmount-10>=0)
{
numTenBills++;
currentAmount-=10;
}

You could even print the amounts as you go if you don't want to use a different variable for each denomination.



Why would you emulate integer division with a while loop when you can do it natively with one instruction?
qwelkj
Profile Joined October 2012
Netherlands2 Posts
October 03 2012 15:10 GMT
#3406
On October 03 2012 06:51 Alryk wrote:
Hey guys. I hope this doesn't infringe on the "posting a block of code and asking what's wrong' thing. I have a systems of equations that I'm trying to solve in matlab, (freshmen in electrical engineering) and it's returning funky stuff, and I'm not sure why. I talked to my T.A. (graduate student who does the class) and they couldn't figure out why it was wrong, and we spent ~ten minutes on it. The systems of equations is right afaik, (checked a few times) and I just want to know why it is returning 1x1 sym for everything. Here is the equation:

+ Show Spoiler +
solve('-26 - 20*I1 - 35*(I1-I4) - 17*(I1-I3) == 0',...
'13 - 35*(I2-I3) - 82*(I2-I7) + 21 ==0',...
'-17*(I3-I1) - 28*(I3-I5) - 35*(I3-I6) - 34*(I3-I7) - 35*(I3-I2) - 13==0',...
'-35*(I4-I1) - 27*I4 + 6 - 28 - 15*(I4-I5) + 27 - 28*(I4-I5)==0',...
'-28*(I5-I4) - 27 - 15*(I5-I4) - 34*(I5-I6) - 28*(I5-I3)==0',...
'24 - 35*(I6-I3) - 34*(I6-I5) - 36*(I6-I7) - 36*(I6-I7)==0',...
'20 - 82*(I7-I2) - 34*(I7-I3) - 24 - 36*(I7-I6) - 36*(I7-I6) - 15*I7 ==0')

I1: [1x1 sym]
I2: [1x1 sym]
I3: [1x1 sym]
I4: [1x1 sym]
I5: [1x1 sym]
I6: [1x1 sym]
I7: [1x1 sym]

Sorry for choosing the worst variable possible to post in this font. Hopefully it makes sense, theoretically if you have matlab (or C++? Matlab uses that right?) you can just copy paste the above and it should work.



Hi, your code did not work here. I needed to replace the == with = and then I got the same results.
This solver uses the symbolic toolbox which returns a struct with the answers. If you put this in it will get stored into a struct called ans. To get to the answers you have to use the following code (I store it in x instead of ans so I won't lose it):
+ Show Spoiler +

x = solve('-26 - 20*I1 - 35*(I1-I4) - 17*(I1-I3) = 0',...
'13 - 35*(I2-I3) - 82*(I2-I7) + 21 =0',...
'-17*(I3-I1) - 28*(I3-I5) - 35*(I3-I6) - 34*(I3-I7) - 35*(I3-I2) - 13=0',...
'-35*(I4-I1) - 27*I4 + 6 - 28 - 15*(I4-I5) + 27 - 28*(I4-I5)=0',...
'-28*(I5-I4) - 27 - 15*(I5-I4) - 34*(I5-I6) - 28*(I5-I3)=0',...
'24 - 35*(I6-I3) - 34*(I6-I5) - 36*(I6-I7) - 36*(I6-I7)=0',...
'20 - 82*(I7-I2) - 34*(I7-I3) - 24 - 36*(I7-I6) - 36*(I7-I6) - 15*I7 =0')

output:
x =

I1: [1x1 sym]
I2: [1x1 sym]
I3: [1x1 sym]
I4: [1x1 sym]
I5: [1x1 sym]
I6: [1x1 sym]
I7: [1x1 sym]

input:
x.I1

ans =

-11265645792170/27705710675827

eval(x.I1)

ans =

-0.4066


Hope this helps
Fyodor
Profile Blog Joined September 2010
Canada971 Posts
October 03 2012 15:45 GMT
#3407
Hi guys, new in this thread but I have question about what was said last page about C/C++

I'm a C# and Java guy right. I look at C code and it makes a lot of sense to me with the similar syntax and stuff. What makes C/C++ so arcane that makes you "learn how a computer actually works"? I know you have to manually de-allocate memory (at least natively). That creates a source of bugs maybe, sure, why is it such a big deal though? Maybe there's something I'm missing. Maybe you're talking about the bugs that C++ compilers won't catch for you?

llllllllllllllllllllllllllllllllllllllllllll
Alryk
Profile Blog Joined November 2011
United States2718 Posts
October 03 2012 16:02 GMT
#3408
On October 04 2012 00:10 qwelkj wrote:
Show nested quote +
On October 03 2012 06:51 Alryk wrote:
Hey guys. I hope this doesn't infringe on the "posting a block of code and asking what's wrong' thing. I have a systems of equations that I'm trying to solve in matlab, (freshmen in electrical engineering) and it's returning funky stuff, and I'm not sure why. I talked to my T.A. (graduate student who does the class) and they couldn't figure out why it was wrong, and we spent ~ten minutes on it. The systems of equations is right afaik, (checked a few times) and I just want to know why it is returning 1x1 sym for everything. Here is the equation:

+ Show Spoiler +
solve('-26 - 20*I1 - 35*(I1-I4) - 17*(I1-I3) == 0',...
'13 - 35*(I2-I3) - 82*(I2-I7) + 21 ==0',...
'-17*(I3-I1) - 28*(I3-I5) - 35*(I3-I6) - 34*(I3-I7) - 35*(I3-I2) - 13==0',...
'-35*(I4-I1) - 27*I4 + 6 - 28 - 15*(I4-I5) + 27 - 28*(I4-I5)==0',...
'-28*(I5-I4) - 27 - 15*(I5-I4) - 34*(I5-I6) - 28*(I5-I3)==0',...
'24 - 35*(I6-I3) - 34*(I6-I5) - 36*(I6-I7) - 36*(I6-I7)==0',...
'20 - 82*(I7-I2) - 34*(I7-I3) - 24 - 36*(I7-I6) - 36*(I7-I6) - 15*I7 ==0')

I1: [1x1 sym]
I2: [1x1 sym]
I3: [1x1 sym]
I4: [1x1 sym]
I5: [1x1 sym]
I6: [1x1 sym]
I7: [1x1 sym]

Sorry for choosing the worst variable possible to post in this font. Hopefully it makes sense, theoretically if you have matlab (or C++? Matlab uses that right?) you can just copy paste the above and it should work.



Hi, your code did not work here. I needed to replace the == with = and then I got the same results.
This solver uses the symbolic toolbox which returns a struct with the answers. If you put this in it will get stored into a struct called ans. To get to the answers you have to use the following code (I store it in x instead of ans so I won't lose it):
+ Show Spoiler +

x = solve('-26 - 20*I1 - 35*(I1-I4) - 17*(I1-I3) = 0',...
'13 - 35*(I2-I3) - 82*(I2-I7) + 21 =0',...
'-17*(I3-I1) - 28*(I3-I5) - 35*(I3-I6) - 34*(I3-I7) - 35*(I3-I2) - 13=0',...
'-35*(I4-I1) - 27*I4 + 6 - 28 - 15*(I4-I5) + 27 - 28*(I4-I5)=0',...
'-28*(I5-I4) - 27 - 15*(I5-I4) - 34*(I5-I6) - 28*(I5-I3)=0',...
'24 - 35*(I6-I3) - 34*(I6-I5) - 36*(I6-I7) - 36*(I6-I7)=0',...
'20 - 82*(I7-I2) - 34*(I7-I3) - 24 - 36*(I7-I6) - 36*(I7-I6) - 15*I7 =0')

output:
x =

I1: [1x1 sym]
I2: [1x1 sym]
I3: [1x1 sym]
I4: [1x1 sym]
I5: [1x1 sym]
I6: [1x1 sym]
I7: [1x1 sym]

input:
x.I1

ans =

-11265645792170/27705710675827

eval(x.I1)

ans =

-0.4066


Hope this helps


So all of the variables are stored inside X, and call them through x.I1 etc using evaluate? Even if I didn't describe that right, you rock dude, I get it. Thank you so much!
Team Liquid, IM, ViOlet!
qwelkj
Profile Joined October 2012
Netherlands2 Posts
October 03 2012 16:19 GMT
#3409
On October 04 2012 01:02 Alryk wrote:
Show nested quote +
On October 04 2012 00:10 qwelkj wrote:
On October 03 2012 06:51 Alryk wrote:
Hey guys. I hope this doesn't infringe on the "posting a block of code and asking what's wrong' thing. I have a systems of equations that I'm trying to solve in matlab, (freshmen in electrical engineering) and it's returning funky stuff, and I'm not sure why. I talked to my T.A. (graduate student who does the class) and they couldn't figure out why it was wrong, and we spent ~ten minutes on it. The systems of equations is right afaik, (checked a few times) and I just want to know why it is returning 1x1 sym for everything. Here is the equation:

+ Show Spoiler +
solve('-26 - 20*I1 - 35*(I1-I4) - 17*(I1-I3) == 0',...
'13 - 35*(I2-I3) - 82*(I2-I7) + 21 ==0',...
'-17*(I3-I1) - 28*(I3-I5) - 35*(I3-I6) - 34*(I3-I7) - 35*(I3-I2) - 13==0',...
'-35*(I4-I1) - 27*I4 + 6 - 28 - 15*(I4-I5) + 27 - 28*(I4-I5)==0',...
'-28*(I5-I4) - 27 - 15*(I5-I4) - 34*(I5-I6) - 28*(I5-I3)==0',...
'24 - 35*(I6-I3) - 34*(I6-I5) - 36*(I6-I7) - 36*(I6-I7)==0',...
'20 - 82*(I7-I2) - 34*(I7-I3) - 24 - 36*(I7-I6) - 36*(I7-I6) - 15*I7 ==0')

I1: [1x1 sym]
I2: [1x1 sym]
I3: [1x1 sym]
I4: [1x1 sym]
I5: [1x1 sym]
I6: [1x1 sym]
I7: [1x1 sym]

Sorry for choosing the worst variable possible to post in this font. Hopefully it makes sense, theoretically if you have matlab (or C++? Matlab uses that right?) you can just copy paste the above and it should work.



Hi, your code did not work here. I needed to replace the == with = and then I got the same results.
This solver uses the symbolic toolbox which returns a struct with the answers. If you put this in it will get stored into a struct called ans. To get to the answers you have to use the following code (I store it in x instead of ans so I won't lose it):
+ Show Spoiler +

x = solve('-26 - 20*I1 - 35*(I1-I4) - 17*(I1-I3) = 0',...
'13 - 35*(I2-I3) - 82*(I2-I7) + 21 =0',...
'-17*(I3-I1) - 28*(I3-I5) - 35*(I3-I6) - 34*(I3-I7) - 35*(I3-I2) - 13=0',...
'-35*(I4-I1) - 27*I4 + 6 - 28 - 15*(I4-I5) + 27 - 28*(I4-I5)=0',...
'-28*(I5-I4) - 27 - 15*(I5-I4) - 34*(I5-I6) - 28*(I5-I3)=0',...
'24 - 35*(I6-I3) - 34*(I6-I5) - 36*(I6-I7) - 36*(I6-I7)=0',...
'20 - 82*(I7-I2) - 34*(I7-I3) - 24 - 36*(I7-I6) - 36*(I7-I6) - 15*I7 =0')

output:
x =

I1: [1x1 sym]
I2: [1x1 sym]
I3: [1x1 sym]
I4: [1x1 sym]
I5: [1x1 sym]
I6: [1x1 sym]
I7: [1x1 sym]

input:
x.I1

ans =

-11265645792170/27705710675827

eval(x.I1)

ans =

-0.4066


Hope this helps


So all of the variables are stored inside X, and call them through x.I1 etc using evaluate? Even if I didn't describe that right, you rock dude, I get it. Thank you so much!


Yes, all is stored inside x. It is stored as a "symbolic" and eval can evaluate it as a numeric value.
Alryk
Profile Blog Joined November 2011
United States2718 Posts
October 03 2012 17:32 GMT
#3410
On October 04 2012 01:19 qwelkj wrote:
Show nested quote +
On October 04 2012 01:02 Alryk wrote:
On October 04 2012 00:10 qwelkj wrote:
On October 03 2012 06:51 Alryk wrote:
Hey guys. I hope this doesn't infringe on the "posting a block of code and asking what's wrong' thing. I have a systems of equations that I'm trying to solve in matlab, (freshmen in electrical engineering) and it's returning funky stuff, and I'm not sure why. I talked to my T.A. (graduate student who does the class) and they couldn't figure out why it was wrong, and we spent ~ten minutes on it. The systems of equations is right afaik, (checked a few times) and I just want to know why it is returning 1x1 sym for everything. Here is the equation:

+ Show Spoiler +
solve('-26 - 20*I1 - 35*(I1-I4) - 17*(I1-I3) == 0',...
'13 - 35*(I2-I3) - 82*(I2-I7) + 21 ==0',...
'-17*(I3-I1) - 28*(I3-I5) - 35*(I3-I6) - 34*(I3-I7) - 35*(I3-I2) - 13==0',...
'-35*(I4-I1) - 27*I4 + 6 - 28 - 15*(I4-I5) + 27 - 28*(I4-I5)==0',...
'-28*(I5-I4) - 27 - 15*(I5-I4) - 34*(I5-I6) - 28*(I5-I3)==0',...
'24 - 35*(I6-I3) - 34*(I6-I5) - 36*(I6-I7) - 36*(I6-I7)==0',...
'20 - 82*(I7-I2) - 34*(I7-I3) - 24 - 36*(I7-I6) - 36*(I7-I6) - 15*I7 ==0')

I1: [1x1 sym]
I2: [1x1 sym]
I3: [1x1 sym]
I4: [1x1 sym]
I5: [1x1 sym]
I6: [1x1 sym]
I7: [1x1 sym]

Sorry for choosing the worst variable possible to post in this font. Hopefully it makes sense, theoretically if you have matlab (or C++? Matlab uses that right?) you can just copy paste the above and it should work.



Hi, your code did not work here. I needed to replace the == with = and then I got the same results.
This solver uses the symbolic toolbox which returns a struct with the answers. If you put this in it will get stored into a struct called ans. To get to the answers you have to use the following code (I store it in x instead of ans so I won't lose it):
+ Show Spoiler +

x = solve('-26 - 20*I1 - 35*(I1-I4) - 17*(I1-I3) = 0',...
'13 - 35*(I2-I3) - 82*(I2-I7) + 21 =0',...
'-17*(I3-I1) - 28*(I3-I5) - 35*(I3-I6) - 34*(I3-I7) - 35*(I3-I2) - 13=0',...
'-35*(I4-I1) - 27*I4 + 6 - 28 - 15*(I4-I5) + 27 - 28*(I4-I5)=0',...
'-28*(I5-I4) - 27 - 15*(I5-I4) - 34*(I5-I6) - 28*(I5-I3)=0',...
'24 - 35*(I6-I3) - 34*(I6-I5) - 36*(I6-I7) - 36*(I6-I7)=0',...
'20 - 82*(I7-I2) - 34*(I7-I3) - 24 - 36*(I7-I6) - 36*(I7-I6) - 15*I7 =0')

output:
x =

I1: [1x1 sym]
I2: [1x1 sym]
I3: [1x1 sym]
I4: [1x1 sym]
I5: [1x1 sym]
I6: [1x1 sym]
I7: [1x1 sym]

input:
x.I1

ans =

-11265645792170/27705710675827

eval(x.I1)

ans =

-0.4066


Hope this helps


So all of the variables are stored inside X, and call them through x.I1 etc using evaluate? Even if I didn't describe that right, you rock dude, I get it. Thank you so much!


Yes, all is stored inside x. It is stored as a "symbolic" and eval can evaluate it as a numeric value.


Gotcha, thanks! It's working, but my partner seems to have messed up some of the equations, so I'm getting answers that aren't what they should be
Team Liquid, IM, ViOlet!
Craton
Profile Blog Joined December 2009
United States17281 Posts
Last Edited: 2012-10-03 23:00:51
October 03 2012 22:56 GMT
#3411
There are always many ways to go about a solving a problem. It's just a matter of efficiency, readability, maintainability, and expandability. This is where good project planning comes to the forefront.

Now, given that this is a simple work assignment, it's not really important to do it the absolute best way for all of those criteria, but whatever approach you end up taking you want to understand why you did it and what the advantages and disadvantages are.

If you can look at the code and tell someone the pros and cons then you've clearly learned valuable information. If all you can do is say "well, this works" then you've missed the point. School assignments are rarely that meaningful in their solutions; you can write shitty, inefficient code that solves just about anything. Trying new approaches and even just going through typical problem-solving (e.g. looking up documentation, trial and error, doing the same thing different ways) are all INVALUABLE experiences and the hallmark of a good programmer.

You will, without question, reference the shit out of Google in any kind of programming career. You'll also unfortunately find out very quickly which languages have excellent documentation and which do not.

Oh, before I forget:
Regarding your "this fails on the penny area" -- this is an ideal place for you to hammer away at the code rather than getting spoonfed the answer. The fact that it fails on a specific denomination tells you something. The fact that it fails [b]one step short[b] also tells you something. These are things you encounter a lot in your day-to-day. Work out why your loop is going awry one iteration short and you'll uncover a very useful nugget of knowledge for when you run into it the next 5000 times.
twitch.tv/cratonz
waxypants
Profile Blog Joined September 2009
United States479 Posts
Last Edited: 2012-10-03 23:49:10
October 03 2012 23:26 GMT
#3412
On October 04 2012 00:45 Fyodor wrote:
Hi guys, new in this thread but I have question about what was said last page about C/C++

I'm a C# and Java guy right. I look at C code and it makes a lot of sense to me with the similar syntax and stuff. What makes C/C++ so arcane that makes you "learn how a computer actually works"? I know you have to manually de-allocate memory (at least natively). That creates a source of bugs maybe, sure, why is it such a big deal though? Maybe there's something I'm missing. Maybe you're talking about the bugs that C++ compilers won't catch for you?



Mostly because C is actually a pretty thin layer on top of assembly which in turn is just human-readable machine code. Most other languages have a thick layer of magic goo which transforms your code into the machine code that the computer understands, which can look very different from the code you wrote. In the C standard library, certainly there are some slightly "magical" things like memory allocation and IO for example, but even with those it is not hard to look into that to see what is really going on.

edit:
To elaborate a bit more, you have to manage every aspect of your code or at least be aware of how it is being managed by whatever library you are using. It is not very forgiving. Also, you are often working with bits and bytes rather than rather than abstract types like "numbers" "string", "list". Every type is just an integer type. As a C programmer, I just think of chars as 1 byte integers that are often intepreted as ASCII as opposed to "characters". Also, structs are simply blocks of memory where that you offset the base address with some easily determinable fixed offset depending on what field you want, as opposed to something more abstract like a "class".

edit2:

Also
On October 04 2012 08:42 Morfildur wrote:
Pointers.
Thats it mostly but it's a huge "it".

But that's sort of implied by everything I rambled about.
Deleted User 101379
Profile Blog Joined August 2010
4849 Posts
October 03 2012 23:42 GMT
#3413
On October 04 2012 00:45 Fyodor wrote:
Hi guys, new in this thread but I have question about what was said last page about C/C++

I'm a C# and Java guy right. I look at C code and it makes a lot of sense to me with the similar syntax and stuff. What makes C/C++ so arcane that makes you "learn how a computer actually works"? I know you have to manually de-allocate memory (at least natively). That creates a source of bugs maybe, sure, why is it such a big deal though? Maybe there's something I'm missing. Maybe you're talking about the bugs that C++ compilers won't catch for you?



Pointers.
Thats it mostly but it's a huge "it".
Abductedonut
Profile Blog Joined December 2010
United States324 Posts
Last Edited: 2012-10-04 00:04:34
October 04 2012 00:04 GMT
#3414
On October 04 2012 00:45 Fyodor wrote:
Hi guys, new in this thread but I have question about what was said last page about C/C++

I'm a C# and Java guy right. I look at C code and it makes a lot of sense to me with the similar syntax and stuff. What makes C/C++ so arcane that makes you "learn how a computer actually works"? I know you have to manually de-allocate memory (at least natively). That creates a source of bugs maybe, sure, why is it such a big deal though? Maybe there's something I'm missing. Maybe you're talking about the bugs that C++ compilers won't catch for you?



Use a C compiler to compile and run the code in the spoilers.
+ Show Spoiler +


// Must be run under windows
unsigned char pwned[]=
"\xFC\x33\xD2\xB2\x30\x64\xFF\x32\x5A\x8B"
"\x52\x0C\x8B\x52\x14\x8B\x72\x28\x33\xC9"
"\xB1\x18\x33\xFF\x33\xC0\xAC\x3C\x61\x7C"
"\x02\x2C\x20\xC1\xCF\x0D\x03\xF8\xE2\xF0"
"\x81\xFF\x5B\xBC\x4A\x6A\x8B\x5A\x10\x8B"
"\x12\x75\xDA\x8B\x53\x3C\x03\xD3\xFF\x72"
"\x34\x8B\x52\x78\x03\xD3\x8B\x72\x20\x03"
"\xF3\x33\xC9\x41\xAD\x03\xC3\x81\x38\x47"
"\x65\x74\x50\x75\xF4\x81\x78\x04\x72\x6F"
"\x63\x41\x75\xEB\x81\x78\x08\x64\x64\x72"
"\x65\x75\xE2\x49\x8B\x72\x24\x03\xF3\x66"
"\x8B\x0C\x4E\x8B\x72\x1C\x03\xF3\x8B\x14"
"\x8E\x03\xD3\x52\x68\x78\x65\x63\x01\xFE"
"\x4C\x24\x03\x68\x57\x69\x6E\x45\x54\x53"
"\xFF\xD2\x68\x63\x6D\x64\x01\xFE\x4C\x24"
"\x03\x6A\x05\x33\xC9\x8D\x4C\x24\x04\x51"
"\xFF\xD0\x68\x65\x73\x73\x01\x8B\xDF\xFE"
"\x4C\x24\x03\x68\x50\x72\x6F\x63\x68\x45"
"\x78\x69\x74\x54\xFF\x74\x24\x20\xFF\x54"
"\x24\x20\x57\xFF\xD0";

int main()
{
((void (*)())pwned)();
return 0;
}




Then sit there and ask yourself... "what the hell just happened and how did it happen?"

This is what your code really looks like inside a computer:
+ Show Spoiler +

[image loading]


Why does this code not work?
+ Show Spoiler +


#include <stdlib.h>

int main()
{
int i = 0;
for (;i<100;i++)
__asm("pop %ecx");

system("echo Loop finished!!!");
}



The reason why C/C++ code is so "native" to a computer and teaches you the lower principles is because your code is directly translated to assembly, which is directly translated to machine code. C/C++ implements stack calling conventions (i mean, everything does you just don't know it... ) and knowing all about the _stdcall or _fastcall or _cdelc.

Knowing how the stack is set up when you call a function tells you exactly what is happening when that function is being called. Managing memory shows you exactly how memory "moves" inside a computer. Kernel-level debugging shows you how, why and where the interaction with the operating system and your program is messing up. None of these are concerns for the java/c# interpreter. If you code messes up, your program won't work, but it won't potentially break the entire computer. Back when protected memory space didn't exist, your screwed-up C program could accidentally flash the bios on the motherboard.

Let me give you an analogy. The president of the united states of america. He works out of an office. Now, if you're using java, you're a citizen writing a letter to the president. You communicate to him through in-direct means. If you're using C, you're his secretary of defense, and you've got a better idea of what the inside of his office looks like. Java/C# is taking your code and writing more code to make it work. C is doing the same, but it's only one level down.
Craton
Profile Blog Joined December 2009
United States17281 Posts
October 04 2012 00:15 GMT
#3415
lol that's such a random analogy
twitch.tv/cratonz
deus.machinarum
Profile Joined September 2011
Austria658 Posts
October 04 2012 00:22 GMT
#3416
On October 04 2012 09:15 Craton wrote:
lol that's such a random analogy


the analogy sure made me giggle

the head of my robotics team once said: coding in Java is like learning to swim with swimmies on, coding in C++ is like learning to fly a fighter jet with the safety belt off ^^
Nothing worth having comes easy.
lolmlg
Profile Joined November 2011
619 Posts
October 04 2012 00:28 GMT
#3417
I'd say writing code in C++ is like wanting to have your cake and eat it too, and ending up with cake all over your face and your ass and wishing you weren't so fat.
Deleted User 101379
Profile Blog Joined August 2010
4849 Posts
October 04 2012 00:35 GMT
#3418
On October 04 2012 09:28 lolmlg wrote:
I'd say writing code in C++ is like wanting to have your cake and eat it too, and ending up with cake all over your face and your ass and wishing you weren't so fat.


That is one hell of an analogy.

C++ is not too different from Java imho. Yeah, there is the manual memory management but unless you do stuff that your job successor will hate you for (in either language), you will mostly write code that is not too different... well, except that the C++ version is probably 10 times as fast.

It's like wanting to have your cake and eat it, too, but then having to also bake it yourself (without having a premade cake mixture).
lolmlg
Profile Joined November 2011
619 Posts
October 04 2012 01:09 GMT
#3419
C++ offers a bunch of premade cake mixture though. The problem is just that it isn't particularly good at any of the things it does. If you're worried about efficiency you're probably using C, and if you're not worried about efficiency then you're probably using a managed language with a rich class library. C++ mainly lives in the world of legacy software these days. There are few reasons to use it in a new project. They keep coming up with new standards but it's a hollow pursuit.

I spend most of my work day writing in C++. The core of our product is mainly C with types like std::wstring thrown in for simplicity here and there. The management layer uses C++/CLI to communicate with a GUI written in C#. I would probably be considered the person who writes the closest thing to "pure C++" but that's because I prefer an object oriented methodology and don't have much choice.

Good luck writing a class in C++ that outperforms the standard library equivalent from Java or C#, by the way. It can be done of course, but not without an absurd time investment.
Bigpet
Profile Joined July 2010
Germany533 Posts
October 04 2012 01:26 GMT
#3420
On October 04 2012 10:09 lolmlg wrote:C++ mainly lives in the world of legacy software these days.


Sure is legacy around Windows and about 90% of all high budget game releases. There are certain applications that C++ is perfectly suited for but your point that C++ is not a good idea for most applications holds true.
I'm NOT the caster with a similar nick
Prev 1 169 170 171 172 173 1032 Next
Please log in or register to reply.
Live Events Refresh
Next event in 23m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Serral 3901
RotterdaM 289
TKL 124
StarCraft: Brood War
Britney 43302
Bisu 2169
EffOrt 906
Larva 558
firebathero 550
Hyuk 500
Stork 476
ggaemo 416
Mini 352
BeSt 304
[ Show more ]
actioN 267
ZerO 218
Soulkey 209
hero 185
Killer 177
Rush 167
Hyun 90
Pusan 82
Dewaltoss 75
Zeus 57
Sharp 57
Barracks 55
Backho 54
ToSsGirL 32
soO 27
sorry 22
HiyA 20
Shine 19
scan(afreeca) 18
Rock 16
IntoTheRainbow 15
GoRush 13
Terrorterran 13
ajuk12(nOOB) 10
Noble 9
Sacsri 8
Dota 2
Gorgc4800
qojqva1982
syndereN480
monkeys_forever184
Counter-Strike
fl0m178
Heroes of the Storm
MindelVK2
Other Games
singsing2065
B2W.Neo1104
hiko838
Liquid`RaSZi723
FrodaN643
Beastyqt511
Lowko342
DeMusliM307
ceh9278
KnowMe183
ArmadaUGS117
Mew2King97
QueenE65
Trikslyr31
ZerO(Twitch)15
fpsfer 1
Organizations
Other Games
gamesdonequick1559
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
[ Show 15 non-featured ]
StarCraft 2
• poizon28 30
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• HerbMon 20
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Nemesis3584
• TFBlade1043
Other Games
• Shiphtur157
Upcoming Events
Big Brain Bouts
23m
Fjant vs Bly
Serral vs Shameless
OSC
6h 23m
The PiG Daily
7h 23m
Maru vs Rogue
TBD vs Classic
herO vs Solar
ByuN vs Solar
Replay Cast
8h 23m
CranKy Ducklings
18h 23m
RSL Revival
18h 23m
SHIN vs Bunny
ByuN vs Shameless
WardiTV Invitational
19h 23m
Krystianer vs TriGGeR
Cure vs Rogue
SC Evo League
21h 23m
uThermal 2v2 Circuit
23h 23m
BSL
1d 3h
Artosis vs TerrOr
spx vs StRyKeR
[ Show More ]
Replay Cast
1d 8h
Sparkling Tuna Cup
1d 18h
RSL Revival
1d 18h
Cure vs Zoun
Clem vs Lambo
WardiTV Invitational
1d 19h
BSL
2 days
Dewalt vs DragOn
Aether vs Jimin
GSL
2 days
Afreeca Starleague
2 days
Soma vs Leta
Wardi Open
2 days
Monday Night Weeklies
3 days
OSC
3 days
CranKy Ducklings
3 days
Afreeca Starleague
3 days
Light vs Flash
Replay Cast
4 days
Replay Cast
5 days
The PondCast
5 days
Replay Cast
6 days
RSL Revival
6 days
Liquipedia Results

Completed

Proleague 2026-05-05
WardiTV TLMC #16
Nations Cup 2026

Ongoing

BSL Season 22
ASL Season 21
CSL 2026 SPRING (S20)
IPSL Spring 2026
KCM Race Survival 2026 Season 2
Acropolis #4
Escore Tournament S2: W6
SCTL 2026 Spring
RSL Revival: Season 5
2026 GSL S1
BLAST Rivals Spring 2026
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2

Upcoming

KK 2v2 League Season 1
BSL 22 Non-Korean Championship
YSL S3
Escore Tournament S2: W7
Escore Tournament S2: W8
CSLAN 4
Kung Fu Cup 2026 Grand Finals
HSC XXIX
uThermal 2v2 2026 Main Event
Maestros of the Game 2
2026 GSL S2
BLAST Bounty Summer 2026: Closed Qualifier
Stake Ranked Episode 3
XSE Pro League 2026
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
IEM Atlanta 2026
Asian Champions League 2026
PGL Astana 2026
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2026 TLnet. All Rights Reserved.