• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 09:21
CET 15:21
KST 23:21
  • 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
Rongyi Cup S3 - RO16 Preview3herO wins SC2 All-Star Invitational10SC2 All-Star Invitational: Tournament Preview5RSL Revival - 2025 Season Finals Preview8RSL Season 3 - Playoffs Preview0
Community News
Weekly Cups (Jan 12-18): herO, MaxPax, Solar win0BSL Season 2025 - Full Overview and Conclusion8Weekly Cups (Jan 5-11): Clem wins big offline, Trigger upsets4$21,000 Rongyi Cup Season 3 announced (Jan 22-Feb 7)19Weekly Cups (Dec 29-Jan 4): Protoss rolls, 2v2 returns7
StarCraft 2
General
[Short Story] The Last GSL StarCraft 2 not at the Esports World Cup 2026 Oliveira Would Have Returned If EWC Continued Stellar Fest "01" Jersey Charity Auction PhD study /w SC2 - help with a survey!
Tourneys
OSC Season 13 World Championship $21,000 Rongyi Cup Season 3 announced (Jan 22-Feb 7) $70 Prize Pool Ladder Legends Academy Weekly Open! SC2 All-Star Invitational: Jan 17-18 Sparkling Tuna Cup - Weekly Open Tournament
Strategy
Simple Questions Simple Answers
Custom Maps
[A] Starcraft Sound Mod
External Content
Mutation # 509 Doomsday Report Mutation # 508 Violent Night Mutation # 507 Well Trained Mutation # 506 Warp Zone
Brood War
General
[ASL21] Potential Map Candidates BW General Discussion Gypsy to Korea Which foreign pros are considered the best? BW AKA finder tool
Tourneys
Azhi's Colosseum - Season 2 [Megathread] Daily Proleagues Small VOD Thread 2.0 [BSL21] Non-Korean Championship - Starts Jan 10
Strategy
Simple Questions, Simple Answers Current Meta Soma's 9 hatch build from ASL Game 2 Game Theory for Starcraft
Other Games
General Games
Nintendo Switch Thread Battle Aces/David Kim RTS Megathread Stormgate/Frost Giant Megathread Beyond All Reason Awesome Games Done Quick 2026!
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
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
Community
General
US Politics Mega-thread NASA and the Private Sector Canadian Politics Mega-thread Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine
Fan Clubs
The herO Fan Club! The IdrA Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece
Sports
2024 - 2026 Football Thread
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
How Esports Advertising Shap…
TrAiDoS
My 2025 Magic: The Gathering…
DARKING
Life Update and thoughts.
FuDDx
How do archons sleep?
8882
James Bond movies ranking - pa…
Topin
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1284 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 States17274 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 States17274 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
RongYI Cup
11:00
Group B
Zoun vs ShoWTimELIVE!
RotterdaM1156
ComeBackTV 946
mouzHeroMarine353
IndyStarCraft 262
Rex124
BRAT_OK 117
3DClanTV 60
EnkiAlexander 55
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
RotterdaM 1156
mouzHeroMarine 353
IndyStarCraft 262
Rex 124
ProTech120
BRAT_OK 117
CosmosSc2 90
StarCraft: Brood War
Calm 6585
Horang2 2704
PianO 1891
Stork 761
GuemChi 636
BeSt 623
Larva 543
Jaedong 482
Light 399
ggaemo 383
[ Show more ]
Soulkey 287
Shuttle 282
Snow 268
Hyuk 255
firebathero 234
Sharp 186
Mong 143
Mind 83
hero 81
Hyun 80
Backho 69
Killer 69
yabsab 62
Shine 48
JYJ 41
ToSsGirL 33
Shinee 32
Barracks 29
Free 28
scan(afreeca) 26
910 21
Hm[arnc] 18
Terrorterran 18
zelot 16
Sexy 8
Dota 2
singsing2670
qojqva1978
XcaliburYe169
canceldota54
febbydoto18
Counter-Strike
olofmeister1963
kennyS1729
zeus1177
markeloff115
edward102
kRYSTAL_23
Other Games
B2W.Neo1616
crisheroes355
Hui .187
XaKoH 130
QueenE73
Mew2King68
djWHEAT41
ArmadaUGS20
Organizations
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 15 non-featured ]
StarCraft 2
• StrangeGG 48
• Kozan
• Migwel
• AfreecaTV YouTube
• intothetv
• sooper7s
• IndyKCrew
• LaughNgamezSOOP
• Laughngamez YouTube
StarCraft: Brood War
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• C_a_k_e 3804
League of Legends
• Jankos2691
• TFBlade974
Upcoming Events
Big Brain Bouts
2h 39m
Percival vs Gerald
Serral vs MaxPax
RongYI Cup
20h 39m
SHIN vs Creator
Classic vs Percival
OSC
22h 39m
BSL 21
1d
RongYI Cup
1d 20h
Maru vs Cyan
Solar vs Krystianer
uThermal 2v2 Circuit
1d 21h
BSL 21
2 days
Wardi Open
2 days
Monday Night Weeklies
3 days
OSC
3 days
[ Show More ]
WardiTV Invitational
3 days
WardiTV Invitational
4 days
The PondCast
5 days
Liquipedia Results

Completed

Proleague 2026-01-20
OSC Championship Season 13
NA Kuram Kup

Ongoing

C-Race Season 1
BSL 21 Non-Korean Championship
CSL 2025 WINTER (S19)
KCM Race Survival 2026 Season 1
Escore Tournament S1: W5
Rongyi Cup S3
Underdog Cup #3
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
eXTREMESLAND 2025
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025

Upcoming

Acropolis #4 - TS4
Acropolis #4
IPSL Spring 2026
uThermal 2v2 2026 Main Event
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
Nations Cup 2026
Tektek Cup #1
PGL Bucharest 2026
Stake Ranked Episode 1
BLAST Open Spring 2026
ESL Pro League Season 23
ESL Pro League Season 23
PGL Cluj-Napoca 2026
IEM Kraków 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.