|
If you're using C++ then a stringstream will do the trick for you:
#include <string>
#include <sstream>
int main()
{
std::string full_name( "Ashley Christopher Munday" );
std::istringstream in_str( full_name );
std::string first_name, second_name, surname;
in_str >> first_name >> second_name >> surname;
std::cout << first_name[ 0 ] << ". " << second_name[ 0 ] << ". " << surname << std::endl;
}
It's potentially less efficient than superman's method above but you don't have to sod about with pointers and overwriting static buffers.
Cheers,
Ash
Edit 'cause I confused two members I was referring to, sorry!
|
|
|
|
|
Hi All,
I was going through IBM's notes on C++ . Get confused by following sentences
"References and pointers cannot be used on constructors and destructors because their addresses cannot be taken "
Can anyone clarify this..?
|
|
|
|
|
What this means is that you cannot take the address of a constructor to assign to a pointer just like you would do with a normal method.
class A
{
public:
A(){}
void One() {}
};
int main()
{
void (A::*pfn)() = &A::One;
void (A::*pfn)() = &A::A;
return 0;
}
|
|
|
|
|
Great...!!!!!!
Thanks a lot << Superman >>>
|
|
|
|
|
Hi sir.
I am trying to change the Button caption
For example :
If the button caption is "Pause"
IOf i click that i am changing the caption as "Continue".
OnButtonClick(){
CButton* pMyButton = (CButton*) GetDlgItem(IDC_MYBUTTONIDC);
pMyButton->SetWindowText("Continue");
}
Now suppose if again i clicked on Continue Button.i
i want to make it as a "Pause" and viceversa
How can i do that.
Any idea will be helpful
Thanks
Raj
|
|
|
|
|
Add a BN_CLICKED handler for the button click.
Inside the function do this -
pMyButton->GetWindowText(cstring);
if (cstring == _T("Continue"))
pMyButton->SetWindowText("Pause");
else
pMyButton->SetWindowText("Continue");
|
|
|
|
|
«_Superman_» wrote: if (cstring == _T("Continue"))
Steve
|
|
|
|
|
CString cstring;
.
.
if (cstring == _T("Continue"))
|
|
|
|
|
I was objecting to the string comparison. I'd prefer to use a flag because:
- Efficiency.
- Maintainability: it will not break if the text on the button is changed and the code not updated.
- i18n.
Steve
|
|
|
|
|
Oh! Of course.
|
|
|
|
|
Hi sir,
I have some database tables which are in MS-Access.
I want to use the same tables in SQL.
Is there any easy way to import the same table in SQL
OR i have to create the same tables in SQL manually.
Thanks
Raj
|
|
|
|
|
Hi I am looking for subroutines to solve linear algebraic equations - fewer unknowns than equations. This subroutine should find the mean of each unknowns and standard deviations. This means that there will be as many as the number of sets of simultaneous equations from N to form M simultaneous equations (permutation). M- number of unknowns, N is the number of equations. N>M.
Thanks
|
|
|
|
|
mrby123 wrote: Hi I am looking for subroutines to solve linear algebraic equations - fewer unknowns than equations
If I remember well, unless some of the equations are linearly dependent, you'll get no solutions for the unknows.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
You are right. I expect the subroutine can determine and exclude those equations linearly dependent to keep only those linearly independent. Then the subroutine solve those linearly independent equations. I assume the number of those linearly independent equations N>M (M is the number of unknowns) still. So the subroutine will get the mean and standard deviation for each unknowns.
Thanks
|
|
|
|
|
Have a look at "Numerical Recipes in C", available for free here[^]: chapter 2 looks promising.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Actually, if there are fewer unknowns than equations, you can have multiple means to solve for the unknowns. This is commonly exploited to check the consistency of equations, etc. The problem is how to ensure that some of the equations are not redundant.
If the equations are inconsistent due to measurement errors or such, then you can use least squares and other techniques to come up with the best estimates (according to some criteria).
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
Thanks for the useful comments.
Yes, the subroutine would check the linear - dependency between equations and exclude those redundent equations.
Yes, a least square technique is required to fine the mean and standard deviations.
|
|
|
|
|
I'm not sure how to remove redundant equations, but in case you need to use least squares to estimate a likely set of parameter values, you'll need to use statistical methods to estimate the precision. In a typical least squares solution, you would look at the variance-covariance matrix and use that to estimate the standard errors in the parameter estimates.
In typical least squares there are some empirical methods to do all of that, but I'm not aware of a general algorithm.
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
Walt Fair, Jr. wrote: The problem is how to ensure that some of the equations are not redundant.
Walt Fair, Jr. wrote: Actually, if there are fewer unknowns than equations
If such equations are not redundant then they are incompatible.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Well, if everything is perfect, then they would be incompatible.
If there are measurement errors or other uncertainties, then they may all be valid estimates. That's exactly the situation that least squares estimates are designed to handle.
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
In the least square estimate you find the set of parameters that best fits the experimental data into the given equation. You have not incompatible equations.
Generally speaking, if you have more independent equations than unknows then you cannot find a solution.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
And Walt is correct that there's a linear algebra method for doing least squares to find the "best" solution to the equations. If you have M equations and N unknowns, you have an MxN matrix times a Nx1 vector of unknowns giving a known Nx1 vector. You multiply both sides by the transpose of the matrix giving an (NxM) x (MxN) x (Nx1) = (Nx1) so you end up with an NxN matrix to do your solution with. If I remember right, the underlying principle is finding the best "projection".
Once you agree to clans, tribes, governments...you've opted for socialism. The rest is just details.
|
|
|
|
|
Simply put, you cannot solve:
x + y = 2
x - y = 0
x + 3y = 4
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
CPallini wrote: Simply put, you cannot solve:
x + y = 2
x - y = 0
x + 3y = 4
You most certainly can find a solution. Whether it makes sense or not depends on what the equations represent. If, due to measurement or statistical errors, they really are representing the same set of parameters, then you can use least squares.
If all have the same importance and have been correctly normalized, etc., blah, blah, you simply find the minimum of:
[(x + y - 2)^2 + (x - y)^2 + (x + 3*y - 4)^2] w.r.t. x and y
If the minimum happens to be zero, the solution is exact. Otherwise it is an estimate of the parameters. The formal mathematical statement of the problem is something like
Find the set of x<small>i</small> that minimizes S = Sum{[f<small>j</small>(x<small>i</small>) - C<small>j</small>]^2}.
You can also add additional constraints to bound the problem and turn it into a nonlinear optimization problem.
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
Yes, you may indeed solve another problem, namely:
Given
f(x,y)=(x+y-2)^2 + (x-y)^2 + (x+3*y-4)^2
find the value of the pair {x,y} which minimize f(x,y).
However, that has not to do with the original linear algebric system.
The algebric system has not solutions according to the Rouché-Capelli theorem (and common sense).
Anyway, might be the OP really needed the solution to the least squares problem (i.e. I misunderstood his requirements), who knows?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|