|
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. |
On March 01 2017 11:40 travis wrote:Would it be possible for anyone to explain what is going on in this practice question for me? Question: The prototype of a function is int *select(void *data);
Define a function pointer variable named fptr that can be assigned the function fptr = select Answer: + Show Spoiler +So I have no idea wtf is going on here. Like, absolutely no idea. I also didn't even understand the question. so our function pointer is int because the function type was in? And the (void *) in the function pointer means what exactly? Does it have to do with the void pointer parameter in the function?
When in doubt, cdecl.org.
|
On March 01 2017 13:01 tofucake wrote:Show nested quote +On March 01 2017 11:50 Blisse wrote: also another thing I grumble about, putting a space between the type and the pointer asterisk. Keep them together! It's type information >_>
int* (*fptr)(void*); I disagree. The asterisk goes with the specific variable because it only applies to one, e.g.: int *a, b;
int* a, b; both are the same semantically the first line makes it clear that only a is a pointer, whereas the second line implies that both a and b are pointers while only a is
Even if this is just a theoretical example, you should never declare variables like that.
[edit] Oh, that was being commented on already.. yeah. What Blisse said.
|
On March 01 2017 17:58 Nesserev wrote:Show nested quote +On March 01 2017 11:40 travis wrote:Would it be possible for anyone to explain what is going on in this practice question for me? Question: The prototype of a function is int *select(void *data);
Define a function pointer variable named fptr that can be assigned the function fptr = select Answer: + Show Spoiler +So I have no idea wtf is going on here. Like, absolutely no idea. I also didn't even understand the question. so our function pointer is int because the function type was in? And the (void *) in the function pointer means what exactly? Does it have to do with the void pointer parameter in the function? Here's a trick when determining the type of a function pointer, just: - replace the name in the function declaration with (* fp) - omit the parameter names. int * king_of_swag(void * data, int * pizza) becomes int * (* fp)(void *, int *)
And then add extra spaces on both sides of * for improved ambiguity?
|
|
|
I don't want the answer but could someone explain how to get started on this?
http://imgur.com/a/R9iEj
I don't really understand. What do a_1, a_2 etc represent? These values can just be anything in Q? How can I possibly solve that?
|
You know how to solve a system of n equations and n variables?
|
Nah, it's just hardmode generics ;o)
|
On March 02 2017 03:53 spinesheath wrote: You know how to solve a system of n equations and n variables?
I guess but that method seems far outside the scope of this class.
edit: well i solved it with a matrix. I am sure there could have been some tricks to make it easier. But I still don't even think this is how I was supposed to solve it.
(ah, seems there was some trick in the lecture slides)
|
On March 02 2017 04:38 travis wrote:Show nested quote +On March 02 2017 03:53 spinesheath wrote: You know how to solve a system of n equations and n variables? I guess but that method seems far outside the scope of this class. edit: well i solved it with a matrix. I am sure there could have been some tricks to make it easier. But I still don't even think this is how I was supposed to solve it. (ah, seems there was some trick in the lecture slides)
The first term of sum 0..n i^p is 1/(p+1). No need to solve the rest if you only want that one.
+ Show Spoiler + P(n, p) = sum 0..n i^p
P(n-1, p) = P(n, p) - n^p = sum 1..(n-1) i^p (because the first term is 0) = sum 0..n (i-1)^p (by transposing the index: i => i-1) = sum 0..n [i^p - p.i^(p-1) + ...] (other terms are polynomial of power below) = P(n, p) - p.P(n, p-1) + ... (by linearity of the sum)
Using the first and last line together, - n^p = - p.P(n, p-1) + ...
P(n, p) = n^(p+1) / (p+1) + O(n^p)
|
On March 02 2017 09:45 Hanh wrote:Show nested quote +On March 02 2017 04:38 travis wrote:On March 02 2017 03:53 spinesheath wrote: You know how to solve a system of n equations and n variables? I guess but that method seems far outside the scope of this class. edit: well i solved it with a matrix. I am sure there could have been some tricks to make it easier. But I still don't even think this is how I was supposed to solve it. (ah, seems there was some trick in the lecture slides) The first term of sum 0..n i^p is 1/(p+1). No need to solve the rest if you only want that one. + Show Spoiler + P(n, p) = sum 0..n i^p
P(n-1, p) = P(n, p) - n^p = sum 1..(n-1) i^p (because the first term is 0) = sum 0..n (i-1)^p (by transposing the index: i => i-1) = sum 0..n [i^p - p.i^(p-1) + ...] (other terms are polynomial of power below) = P(n, p) - p.P(n, p-1) + ... (by linearity of the sum)
Using the first and last line together, - n^p = - p.P(n, p-1) + ...
P(n, p) = n^(p+1) / (p+1) + O(n^p)
Clever! Any easier ways to solve this? I solved the whole sum 0..n i^4 but that's a whole lot of effort, and even gaussian might be faster.
|
On March 02 2017 21:43 slmw wrote:Show nested quote +On March 02 2017 09:45 Hanh wrote:On March 02 2017 04:38 travis wrote:On March 02 2017 03:53 spinesheath wrote: You know how to solve a system of n equations and n variables? I guess but that method seems far outside the scope of this class. edit: well i solved it with a matrix. I am sure there could have been some tricks to make it easier. But I still don't even think this is how I was supposed to solve it. (ah, seems there was some trick in the lecture slides) The first term of sum 0..n i^p is 1/(p+1). No need to solve the rest if you only want that one. + Show Spoiler + P(n, p) = sum 0..n i^p
P(n-1, p) = P(n, p) - n^p = sum 1..(n-1) i^p (because the first term is 0) = sum 0..n (i-1)^p (by transposing the index: i => i-1) = sum 0..n [i^p - p.i^(p-1) + ...] (other terms are polynomial of power below) = P(n, p) - p.P(n, p-1) + ... (by linearity of the sum)
Using the first and last line together, - n^p = - p.P(n, p-1) + ...
P(n, p) = n^(p+1) / (p+1) + O(n^p)
Clever! Any easier ways to solve this? I solved the whole sum 0..n i^4 but that's a whole lot of effort, and even gaussian might be faster.
I didn't even understand what he wrote, LOL I need to write it out on paper instead of just staring at my monitor I guess
ok after staring it for even longer it looks like you are doing weak induction but you are not doing it like we were taught. you replaced n with n-1 instead of n+1
|
It's a variable substitution. By the way, what was the trick from the lecture?
|
On March 03 2017 07:10 travis wrote:Show nested quote +On March 02 2017 21:43 slmw wrote:On March 02 2017 09:45 Hanh wrote:On March 02 2017 04:38 travis wrote:On March 02 2017 03:53 spinesheath wrote: You know how to solve a system of n equations and n variables? I guess but that method seems far outside the scope of this class. edit: well i solved it with a matrix. I am sure there could have been some tricks to make it easier. But I still don't even think this is how I was supposed to solve it. (ah, seems there was some trick in the lecture slides) The first term of sum 0..n i^p is 1/(p+1). No need to solve the rest if you only want that one. + Show Spoiler + P(n, p) = sum 0..n i^p
P(n-1, p) = P(n, p) - n^p = sum 1..(n-1) i^p (because the first term is 0) = sum 0..n (i-1)^p (by transposing the index: i => i-1) = sum 0..n [i^p - p.i^(p-1) + ...] (other terms are polynomial of power below) = P(n, p) - p.P(n, p-1) + ... (by linearity of the sum)
Using the first and last line together, - n^p = - p.P(n, p-1) + ...
P(n, p) = n^(p+1) / (p+1) + O(n^p)
Clever! Any easier ways to solve this? I solved the whole sum 0..n i^4 but that's a whole lot of effort, and even gaussian might be faster. I didn't even understand what he wrote, LOL I need to write it out on paper instead of just staring at my monitor I guess ok after staring it for even longer it looks like you are doing weak induction but you are not doing it like we were taught. you replaced n with n-1 instead of n+1
Not induction. He's using the fact that he can rearrange [sum 0..p i^4] to be of the form[ x * n^5 + O(n^4)], which makes solving x easier since he can ignore any O(n^4) terms. The rest is just set-up for this. Plaintext math is awful to read though.
|
there was no proof, but the trick is that the leading term of the sum of form:
series from i = 1 to n (i^d) where d >= 1
can be approximated with the integral from 1 to n of x^d
which gives a coefficient of 1/(d+1)
|
Ah. Seems rather obvious with lim_(n->inf) but writing a full proof might be tougher.
|
On March 03 2017 10:50 slmw wrote: Ah. Seems rather obvious with lim_(n->inf) but writing a full proof might be tougher.
You have to prove that the residual is O(n^p) - which isn't easy to do for me.
|
On March 01 2017 18:19 Khalum wrote:Show nested quote +On March 01 2017 13:01 tofucake wrote:On March 01 2017 11:50 Blisse wrote: also another thing I grumble about, putting a space between the type and the pointer asterisk. Keep them together! It's type information >_>
int* (*fptr)(void*); I disagree. The asterisk goes with the specific variable because it only applies to one, e.g.: int *a, b;
int* a, b; both are the same semantically the first line makes it clear that only a is a pointer, whereas the second line implies that both a and b are pointers while only a is Even if this is just a theoretical example, you should never declare variables like that. [edit] Oh, that was being commented on already.. yeah. What Blisse said.
I always use
int* a It helps me think of a as a type of "int pointer" even though you need to know the rules of declaration. If you try and declare two pointers on the same line you are going to be disappointed. Especially in this case since your compiler might be able to cast an int* to an int.
I would rarely declare two vars on the same line due to convention. The spacing of the star is also a matter of convention, and mostly in practice I have seen it attached to the type name.
Another convention that helps reduce confusion is initialising pointers will nullptr instead of 0. Also I am very wary of declaring vars without initial values. The amount of hours I've spent debugging uninitialised variables as a rookie, oh geez.
|
|
hanh or slmw or acrofales or anyone else, could you check over this? (really, I just want one step explained in it. anyone who is good at algebra could explain it)
the problem is to prove this sequence with strong induction
sequence:
a_0 = 12 a_1 = 20 (for all n >= 2)[a_n = 2a_(n-1) + 3a_(n-2)
Show that for all n, a_n <= 12*3^n
so my proof was to first show the base cases.
12 <= 12 * 1 20 <= 12*3
Now make inductive hypothesis.
For some k>= a_1, and for every i: 0 <= i <= k, assume that P(i) holds. Therefore a_i = 12*3^i
Now do the inductive step by proving P(K+1):
a_(k+1) = 12 * 3^(k+1)
= 2a_k + 3a_(k-1) = 2(12*3^k)+3(12*3^(k-1)) = 12 * (2*3^k + 3*3^k-1)
and here is where I don't know algebraically what to do next. I mean obviously, (2*3^k + 3*3^(k-1)) = 3^(k+1) But what steps are used to prove that?
|
|
|
|