• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 09:02
CEST 15:02
KST 22:02
  • 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
[ASL19] Finals Recap: Standing Tall9HomeStory Cup 27 - Info & Preview18Classic wins Code S Season 2 (2025)16Code S RO4 & Finals Preview: herO, Rogue, Classic, GuMiho0TL Team Map Contest #5: Presented by Monster Energy6
Community News
Flash Announces Hiatus From ASL54Weekly Cups (June 23-29): Reynor in world title form?13FEL Cracov 2025 (July 27) - $8000 live event16Esports World Cup 2025 - Final Player Roster16Weekly Cups (June 16-22): Clem strikes back1
StarCraft 2
General
Weekly Cups (June 23-29): Reynor in world title form? The SCII GOAT: A statistical Evaluation PiG Sty Festival #5: Playoffs Preview + Groups Recap The GOAT ranking of GOAT rankings Statistics for vetoed/disliked maps
Tourneys
RSL: Revival, a new crowdfunded tournament series Korean Starcraft League Week 77 Master Swan Open (Global Bronze-Master 2) [GSL 2025] Code S: Season 2 - Semi Finals & Finals $5,100+ SEL Season 2 Championship (SC: Evo)
Strategy
How did i lose this ZvP, whats the proper response Simple Questions Simple Answers
Custom Maps
[UMS] Zillion Zerglings
External Content
Mutation # 480 Moths to the Flame Mutation # 479 Worn Out Welcome Mutation # 478 Instant Karma Mutation # 477 Slow and Steady
Brood War
General
Player “Jedi” cheat on CSL BW General Discussion Flash Announces Hiatus From ASL BGH Auto Balance -> http://bghmmr.eu/ Unit and Spell Similarities
Tourneys
[Megathread] Daily Proleagues [BSL20] Grand Finals - Sunday 20:00 CET Small VOD Thread 2.0 [BSL20] GosuLeague RO16 - Tue & Wed 20:00+CET
Strategy
Simple Questions, Simple Answers I am doing this better than progamers do.
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread Path of Exile What do you want from future RTS games? Beyond All Reason
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
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Vanilla Mini Mafia
Community
General
US Politics Mega-thread Trading/Investing Thread Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread The Games Industry And ATVI
Fan Clubs
SKT1 Classic Fan Club! Maru Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece [\m/] Heavy Metal Thread
Sports
Formula 1 Discussion 2024 - 2025 Football Thread NBA General Discussion TeamLiquid Health and Fitness Initiative For 2023 NHL Playoffs 2024
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
Blogs
Culture Clash in Video Games…
TrAiDoS
from making sc maps to makin…
Husyelt
Blog #2
tankgirl
StarCraft improvement
iopq
Trip to the Zoo
micronesia
Customize Sidebar...

Website Feedback

Closed Threads



Active: 654 users

The Big Programming Thread - Page 171

Forum Index > General Forum
Post a Reply
Prev 1 169 170 171 172 173 1031 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 States17246 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 States17246 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 1031 Next
Please log in or register to reply.
Live Events Refresh
WardiTV European League
12:00
Swiss Groups Day 2
WardiTV1198
TKL 366
Liquipedia
CranKy Ducklings
10:00
Master Swan Open #93
CranKy Ducklings86
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
TKL 366
Hui .279
BRAT_OK 84
MindelVK 43
StarCraft: Brood War
Calm 11547
Horang2 2182
Bisu 1330
Jaedong 1212
Flash 1209
Larva 874
Mini 536
BeSt 383
Stork 382
actioN 314
[ Show more ]
Last 206
Soulkey 190
Hyun 163
hero 103
Mind 103
Sea.KH 68
TY 56
sSak 49
Mong 36
Icarus 21
Free 17
HiyA 12
GoRush 11
Terrorterran 1
Stormgate
NightEnD19
Dota 2
XcaliburYe593
canceldota187
Counter-Strike
zeus475
Heroes of the Storm
Khaldor283
Other Games
Gorgc3088
singsing2852
B2W.Neo1352
DeMusliM557
Happy330
Fuzer 264
XaKoH 228
Lowko205
SortOf113
Organizations
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 14 non-featured ]
StarCraft 2
• Adnapsc2 22
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• C_a_k_e 2280
• WagamamaTV692
League of Legends
• Nemesis3053
Upcoming Events
FEL
2h 58m
RSL Revival
20h 58m
Clem vs Classic
SHIN vs Cure
FEL
22h 58m
WardiTV European League
22h 58m
BSL: ProLeague
1d 4h
Dewalt vs Bonyth
Replay Cast
2 days
Sparkling Tuna Cup
2 days
WardiTV European League
3 days
The PondCast
3 days
Replay Cast
4 days
[ Show More ]
RSL Revival
4 days
Replay Cast
5 days
RSL Revival
5 days
RSL Revival
6 days
Liquipedia Results

Completed

BSL 2v2 Season 3
HSC XXVII
Heroes 10 EU

Ongoing

JPL Season 2
BSL Season 20
Acropolis #3
KCM Race Survival 2025 Season 2
CSL 17: 2025 SUMMER
Copa Latinoamericana 4
Championship of Russia 2025
RSL Revival: Season 1
Murky Cup #2
BLAST.tv Austin Major 2025
ESL Impact League Season 7
IEM Dallas 2025
PGL Astana 2025
Asian Champions League '25
BLAST Rivals Spring 2025
MESA Nomadic Masters
CCT Season 2 Global Finals
IEM Melbourne 2025

Upcoming

2025 ACS Season 2: Qualifier
CSLPRO Last Chance 2025
2025 ACS Season 2
CSLPRO Chat StarLAN 3
K-Championship
uThermal 2v2 Main Event
SEL Season 2 Championship
FEL Cracov 2025
Esports World Cup 2025
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
FISSURE Playground #1
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 © 2025 TLnet. All Rights Reserved.