Go Back   Naruto & Bleach Mania Forums > General Discussion > General Discussion & News
User CP Rules & Info Arcade Gallery

http://www.narutomania.com/forums/New Month, New Problems
For these forums to remain up we need $480 within 7 days. Please donate HERE We need this amount no matter what to keep this website up. Thank you for your support.

Reply
 
Thread Tools
Old 04-02-2008, 08:24 PM   #1061
Donator
 
MuKen's Avatar


Join Date: May 2006
Location: New York City
Posts: 2,649
My Mood:
Rep Power: 21
MuKen has a brilliant futureMuKen has a brilliant futureMuKen has a brilliant future

Basic Gold Basic Bronze Basic Silver 
Total Awards: 3

Default Re: Homework Help v1.3

What level is this class? Would they expect you to make use of time-efficient selection algorithms?

If not, the easiest thing to do is to just sort the array and then choose the element at the appropriate index.
MuKen is offline   Reply With Quote
Old 04-02-2008, 08:28 PM   #1062
Genin


Join Date: Oct 2005
Posts: 75
Rep Power: 0
ahme has much to be proud ofahme has much to be proud ofahme has much to be proud of

Basic Bronze 
Total Awards: 1

Default Re: Homework Help v1.3

Quote:
Originally Posted by Ice(v)an View Post
Second Assignment,

finding the kth smallest item in an array. Implement this idea and use it to form the basis for a percentile function. This function should take two arguments, an array or vector of numbers A and a percentile p. It should return the number n in A such that p percent of all items in A are smaller than n.



This specification is intentionally a little imprecise. For example, it will normally be the case that no number in A exactly fits the definition, although one or more comes close. You'll need to decide what to return in that case. Be sure to document your choices and assumptions thoroughly.



Test and demonstrate your percentile function by embedding it in a program that generates sets of random numbers and then finds various percentiles in each set.
I haven't used C++ that much, but here is an algorithm/description of the solution.

Create a class with:
1. One private field that is an array of doubles and let's call it myArray.
2. Constructor that takes an array of doubles as it's argument: The constructor initializes the myArray array to the passed array.
3. Public function that takes a double number as it's argument and returns a double number representing the number n that we want.

pseudo-code/partial code:
class Percentile{

public:
Percentile(double []);
private:
double myArray[];
double getNum(double);
};
Percentile:: Percentile(double nums[]){
myArray = nums;
}
double Percentile::getNum(double p){

double temp[] = myArray;
//1. sort the temp array in ascending order. I think C++ libraries has a sort function or you can create your own sorting function
//2. calculate the index of our target number
// index = (length of the temp array - 1)*p/100 rounded to the nearest integer
// return temp[index]
}

edit: didn't know that someone replied to your post and we have basically said the same thing

Last edited by ahme; 04-02-2008 at 11:23 PM.
ahme is offline   Reply With Quote
Old 04-02-2008, 09:40 PM   #1063
Hunter-nin
 
DeathGuiseX's Avatar


Join Date: Feb 2005
Location: East Side, NERV
Posts: 2,390
My Mood:
Rep Power: 31
DeathGuiseX has a reputation beyond reputeDeathGuiseX has a reputation beyond reputeDeathGuiseX has a reputation beyond reputeDeathGuiseX has a reputation beyond reputeDeathGuiseX has a reputation beyond repute
Send a message via AIM to DeathGuiseX
Default Re: Homework Help v1.3

I just wanna check my work, so can someone do this w/ the work:
∫x³/(x²+1)^(1/2) dx with the limits being 0 --> 1, as in 0 is on the bottom of ∫ representing a and 1 is on the top of ∫ representing b. This is once again, integration by parts.

and also, is ∫sin(3ln x) dx = (xsin(3lnx) - 3xcos(3lnx))/10 . I dont need an explanation on how to do this problem unless I have the wrong answer.
__________________
DeathGuiseX is offline   Reply With Quote
Old 04-02-2008, 10:19 PM   #1064
o({})o


Join Date: Nov 2006
Posts: 98
My Mood:
Rep Power: 0
]MpC[hebe is an unknown quantity at this point
Default Re: Homework Help v1.3

Quote:
Originally Posted by DeathGuiseX View Post
I just wanna check my work, so can someone do this w/ the work:
∫x³/(x²+1)^(1/2) dx with the limits being 0 --> 1, as in 0 is on the bottom of ∫ representing a and 1 is on the top of ∫ representing b. This is once again, integration by parts.

and also, is ∫sin(3ln x) dx = (xsin(3lnx) - 3xcos(3lnx))/10 . I dont need an explanation on how to do this problem unless I have the wrong answer.
The second answer is correct. I don't have time to type out the first question, sorry.
__________________
This is my account for use on public computers.
Please do not PM this account unless you have good reason to believe that I will not be on my main account.
]MpC[hebe is offline   Reply With Quote
Old 04-02-2008, 10:20 PM   #1065
| Northern Cross ~ ♥
 
Atem's Avatar


Join Date: Apr 2005
Location: Gotham City
Posts: 7,563
My Mood:
Rep Power: 74
Atem has a reputation beyond reputeAtem has a reputation beyond reputeAtem has a reputation beyond reputeAtem has a reputation beyond reputeAtem has a reputation beyond reputeAtem has a reputation beyond reputeAtem has a reputation beyond reputeAtem has a reputation beyond reputeAtem has a reputation beyond reputeAtem has a reputation beyond reputeAtem has a reputation beyond repute

Basic Bronze Basic Gold Basic Silver 
Total Awards: 3

Default Re: Homework Help v1.3

I have to do research on Washington for one of my classes, but I can't find anything about what kind of political issues would affect the state. Can someone help me find something or if you already know something, tell me. Thanks.
__________________

Atem is offline   Reply With Quote
Old 04-02-2008, 10:58 PM   #1066
Akatsuki
 
Ice(v)an's Avatar


Join Date: Nov 2004
Location: Urahara Store
Posts: 9,394
My Mood:
Rep Power: 36
Ice(v)an has a brilliant futureIce(v)an has a brilliant futureIce(v)an has a brilliant futureIce(v)an has a brilliant future

Basic Bronze 
Total Awards: 1

Default Re: Homework Help v1.3

We're not concerning about time efficient as of yet.

And also, I haven't really coded much with arrays and such so...
__________________



thanks to Tom, ~Mrge and Simonarturo, EE
Ice(v)an is offline   Reply With Quote
Old 04-02-2008, 11:32 PM   #1067
Donator
 
MuKen's Avatar


Join Date: May 2006
Location: New York City
Posts: 2,649
My Mood:
Rep Power: 21
MuKen has a brilliant futureMuKen has a brilliant futureMuKen has a brilliant future

Basic Gold Basic Bronze Basic Silver 
Total Awards: 3

Default Re: Homework Help v1.3

Quote:
Originally Posted by Ice(v)an View Post
We're not concerning about time efficient as of yet.

And also, I haven't really coded much with arrays and such so...

Yeah, then just sort the array and choose an element from it. You can do this by calling qsort.

For example, say you have an array of 10 ints

Code:
#include <iostream>
#include <stdlib.h>

int A[] = { 8, 1, 9, 2, 7, 4, 5, 3, 0, 6 };

int compare (const void* x, const void* y)
{
  return *((int*)x) - *((int*)y);
}

int main ()
{
  qsort (A, 10, sizeof(int), compare);
  for (int n=0; n<10; n++) {
    cout << A[n] << endl;
  }
  return 0;
}
Would print out

Code:
0
1
2
3
4
5
6
7
8
9
The compare function is something you provide to qsort to tell it how to sort ints.

Last edited by MuKen; 04-02-2008 at 11:42 PM.
MuKen is offline   Reply With Quote
Old 05-02-2008, 03:11 AM   #1068
Genin


Join Date: Oct 2005
Posts: 75
Rep Power: 0
ahme has much to be proud ofahme has much to be proud ofahme has much to be proud of

Basic Bronze 
Total Awards: 1

Default Re: Homework Help v1.3

Quote:
Originally Posted by DeathGuiseX View Post
I just wanna check my work, so can someone do this w/ the work:
∫x³/(x²+1)^(1/2) dx with the limits being 0 --> 1, as in 0 is on the bottom of ∫ representing a and 1 is on the top of ∫ representing b. This is once again, integration by parts.

and also, is ∫sin(3ln x) dx = (xsin(3lnx) - 3xcos(3lnx))/10 . I dont need an explanation on how to do this problem unless I have the wrong answer.
For the first question, it is not a hard problem if you take a moment before you do the integral by parts. Integral by parts is one of those techniques that you have to have a sharp eye to use.
Back to the question...
∫x³/(x²+1)^(1/2)
When choosing the u and dv in you want to make the problem less complicated and one way to make the problem easier is reducing the power of a polynomial. Here we have the polynomial x^3, so I can take u=x^3, but you need to stop and think for a second here because if u=x^3 then dv = (x²+1)^(1/2)dx which will require you to use trig substitution to get v and will involve very ugly looking function which will make the problem even more complicated. But, if you have sharp eyes and remember the trick of having the derivative of the numerator in the denominator (I guess I've said this too many times) then you know that taking your dv = x/(x²+1)^(1/2)dx would make this very easily integrable.
So, take u=x^2 and dv=x/(x²+1)^(1/2)dx and the integral should be very easy to do.
I don't have time to write down the whole solution, but the final answer is
2^(1/2)-2/3*(2^(3/2)-1) which after doing some simplification turns down to be 2/3 - (2^(1/2))/3
ahme is offline   Reply With Quote
Old 05-02-2008, 03:26 AM   #1069
Hunter-nin
 
DeathGuiseX's Avatar


Join Date: Feb 2005
Location: East Side, NERV
Posts: 2,390
My Mood:
Rep Power: 31
DeathGuiseX has a reputation beyond reputeDeathGuiseX has a reputation beyond reputeDeathGuiseX has a reputation beyond reputeDeathGuiseX has a reputation beyond reputeDeathGuiseX has a reputation beyond repute
Send a message via AIM to DeathGuiseX
Default Re: Homework Help v1.3

^Wait, what would v be then? Cause I tried u = x^3, and dv = 1/(x2 + 1)^.5 dx, and got du/3 = x^2 dx and v= 2(x^2 +1)^1/2
and it became 2x^3 (x^2 + 1)^1/2 - 1/3∫2x^2 (x^2 + 1) ^1/2 dx, but I dont know how to do that second integral. Is my v correct? If not, what is v if you use your dv(x/(x²+1)^(1/2) dx)?
Also, I tried putting the integral in my calculator to get a numerical answer and it doesnt match your answer.
__________________
DeathGuiseX is offline   Reply With Quote
Old 05-02-2008, 04:00 AM   #1070
Genin


Join Date: Oct 2005
Posts: 75
Rep Power: 0
ahme has much to be proud ofahme has much to be proud ofahme has much to be proud of

Basic Bronze 
Total Awards: 1

Default Re: Homework Help v1.3

Quote:
Originally Posted by DeathGuiseX View Post
^Wait, what would v be then? Cause I tried u = x^3, and dv = 1/(x2 + 1)^.5 dx, and got du/3 = x^2 dx and v= 2(x^2 +1)^1/2
and it became 2x^3 (x^2 + 1)^1/2 - 1/3∫2x^2 (x^2 + 1) ^1/2 dx, but I dont know how to do that second integral. Is my v correct? If not, what is v if you use your dv(x/(x²+1)^(1/2) dx)?
Also, I tried putting the integral in my calculator to get a numerical answer and it doesnt match your answer.
Quote:
Originally Posted by ahme View Post
So, take u=x^2 and dv=x/(x²+1)^(1/2)dx and the integral should be very easy to do.
I don't have time to write down the whole solution, but the final answer is
2^(1/2)-2/3*(2^(3/2)-1) which after doing some simplification turns down to be 2/3 - (2^(1/2))/3
so du = 2x dx and v = (x²+1)^(1/2)

also, I've double checked my answer I think it's correct. It's (2-2^(1/2))/3

Last edited by ahme; 05-02-2008 at 05:06 AM.
ahme is offline   Reply With Quote
Old 09-02-2008, 03:46 PM   #1071
Chuunin
 
Easybigboi's Avatar


Join Date: Jun 2007
Posts: 441
My Mood:
Rep Power: 6
Easybigboi has a spectacular aura about
Default Re: Homework Help v1.3

Can anyone help me on some english? I need some comparisons between Nicholas Nickleby and Hard Times the books by Charles Dickens preferably the characters i.e Bounderby and Mr Squeers. Any help would be appreciated whether it is your own interpretations or a website link. Thanks
__________________
Easybigboi is offline   Reply With Quote
Old 09-02-2008, 04:43 PM   #1072
the Brown
 
4thseal's Avatar
Join Date: Apr 2007
Location: Never separate me from these stars...
Posts: 11,138
My Mood:
Rep Power: 59
4thseal has disabled reputation

High Gold Award 
Total Awards: 1

Send a message via AIM to 4thseal Send a message via MSN to 4thseal
Default Re: Homework Help v1.3

Here's a resources:

The Life and Adventures of Nicholas Nickleby (Cri...: Information and Much More from Answers.com

^Not the best, though, if you have access to any literary databases, i'm sure you'd have better luck finding what you want. Some questions to ask your self when comparing character: Are there any similar traits between the two? Do they have simulare motives/wants? Do the two characters carry simular allusions in names, clothing, residence, and so on.
__________________

Persistency is a fool's best asset
Exposed #15: Read & Comment

4thseal is offline   Reply With Quote
Old 12-02-2008, 12:23 AM   #1073
P
Chuunin
 
P's Avatar


Join Date: Sep 2004
Posts: 226
My Mood:
Rep Power: 18
P is just really nice
Send a message via MSN to P
Default Re: Homework Help v1.3

Q: Suppose that f is continuous on the interval [0,1] and its strictly positive there. Show that there exists an epsilon > 0 such that f(x) > epsilon in [0,1]. (Hint: one of the hard theorems will help)
__________________

P is online now   Reply With Quote
Old 12-02-2008, 12:47 AM   #1074
Hunter-nin
 
Nivikran's Avatar


Join Date: Sep 2004
Posts: 2,704
My Mood:
Rep Power: 50
Nivikran has a reputation beyond reputeNivikran has a reputation beyond reputeNivikran has a reputation beyond reputeNivikran has a reputation beyond reputeNivikran has a reputation beyond reputeNivikran has a reputation beyond reputeNivikran has a reputation beyond reputeNivikran has a reputation beyond repute

Basic Bronze 
Total Awards: 1

Send a message via MSN to Nivikran
Default Re: Homework Help v1.3

edited
__________________


Last edited by Nivikran; 14-02-2008 at 05:17 AM.
Nivikran is offline   Reply With Quote
Old 12-02-2008, 09:08 PM   #1075
o({})o


Join Date: Nov 2006
Posts: 98
My Mood:
Rep Power: 0
]MpC[hebe is an unknown quantity at this point
Default Re: Homework Help v1.3

Quote:
Originally Posted by P View Post
Q: Suppose that f is continuous on the interval [0,1] and its strictly positive there. Show that there exists an epsilon > 0 such that f(x) > epsilon in [0,1]. (Hint: one of the hard theorems will help)
Seems trivial

The best chance f would have is to have an asymptote y=0, but since f(x) is continuous and positive (> 0), that means y = f(x) has a positive, real value for every x on [0,1]. Any positive real number can be divided by any other positive real number to yield a positive real number (the Reals are a field under addition and multiplication).

So, let f(x) = y and let epsilon = p where y, p > 0

y > y/2 for all y

Therefore, taking the local min of f(x) in [0,1] will offer us a y[sub]min[sub] for which all other y >= ymin.

That in mind, y >= ymin > ymin/2

Let p = ymin/2, and y > p for all y.

Still, that's just a long way of saying something I think is fairly trivial.
__________________
This is my account for use on public computers.
Please do not PM this account unless you have good reason to believe that I will not be on my main account.

Last edited by ]MpC[hebe; 14-02-2008 at 04:42 AM.
]MpC[hebe is offline   Reply With Quote
Old 14-02-2008, 01:24 AM   #1076
Akatsuki
 
Ice(v)an's Avatar


Join Date: Nov 2004
Location: Urahara Store
Posts: 9,394
My Mood:
Rep Power: 36
Ice(v)an has a brilliant futureIce(v)an has a brilliant futureIce(v)an has a brilliant futureIce(v)an has a brilliant future

Basic Bronze 
Total Awards: 1

Default Re: Homework Help v1.3

This function should take two arguments, an array or vector of numbers A and a percentile p. It should return the number n in A such that p percent of all items in A are smaller than n.

----

From the code you guys gave me, I don't see any vectors.

So would the function be something like this?

vector<string> vect;

someFunction(vect, p)
{
return n
}
__________________



thanks to Tom, ~Mrge and Simonarturo, EE
Ice(v)an is offline   Reply With Quote
Old 14-02-2008, 04:29 AM   #1077
Donator
 
MuKen's Avatar


Join Date: May 2006
Location: New York City
Posts: 2,649
My Mood:
Rep Power: 21
MuKen has a brilliant futureMuKen has a brilliant futureMuKen has a brilliant future

Basic Gold Basic Bronze Basic Silver 
Total Awards: 3

Default Re: Homework Help v1.3

They said you could use an array or a vector right?

The code I showed above uses an array...

If you are required to use a vector, I'd just go ahead and fill an array from the vector anyway so you can make use of the qsort function; it saves a lot of work.
MuKen is offline   Reply With Quote
Old 15-02-2008, 12:37 AM   #1078
Akatsuki
 
Ice(v)an's Avatar


Join Date: Nov 2004
Location: Urahara Store
Posts: 9,394
My Mood:
Rep Power: 36
Ice(v)an has a brilliant futureIce(v)an has a brilliant futureIce(v)an has a brilliant futureIce(v)an has a brilliant future

Basic Bronze 
Total Awards: 1

Default Re: Homework Help v1.3

I do have a choice for array or vector, I want to choose vector.

So the post above, did I have the outline right?

If I wrote a function that had two arguments, one vector, and the other P?
__________________



thanks to Tom, ~Mrge and Simonarturo, EE
Ice(v)an is offline   Reply With Quote
Old 15-02-2008, 01:05 AM   #1079
Donator
 
MuKen's Avatar


Join Date: May 2006
Location: New York City
Posts: 2,649
My Mood:
Rep Power: 21
MuKen has a brilliant futureMuKen has a brilliant futureMuKen has a brilliant future

Basic Gold Basic Bronze Basic Silver 
Total Awards: 3

Default

Yeah, that structure is right, though the syntax should be something like

someFunction(vector<int>& vect, double p) {
return n;
}

Last edited by MuKen; 15-02-2008 at 01:06 AM.
MuKen is offline   Reply With Quote
Old 15-02-2008, 04:32 AM   #1080
Akatsuki
 
Ice(v)an's Avatar


Join Date: Nov 2004
Location: Urahara Store
Posts: 9,394
My Mood:
Rep Power: 36
Ice(v)an has a brilliant futureIce(v)an has a brilliant futureIce(v)an has a brilliant futureIce(v)an has a brilliant future

Basic Bronze 
Total Awards: 1

Default Re: Homework Help v1.3

^
do i still have to put Vector<int>&, doublep)

if it's a class, and I have a vector as a private data member?
__________________



thanks to Tom, ~Mrge and Simonarturo, EE
Ice(v)an is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off
Forum Jump