das1404

135 Reputation

6 Badges

12 years, 219 days

MaplePrimes Activity


These are questions asked by das1404

I wish to solve three linear simultaneous equations and obtain the solutions in floating point form.

the following works...

solvec:=fsolve({T+N1-m1=0, N2-N1-m2=0,T-N2-m3=0}, {T,N1,N2});

...but the solutions are given in either symbolic, or equation form.  I would like numbers - floating point form.

Below is my attempt to solve this.  with(plots) & with(plottools) is not necessary for this - but I was doing some related graphic work.  I did try with(RealDomain), but it seemedto make little difference.  I have done a copy & paste of an rtf file, but the Maple output has not come out so well.  Any help would be appreciated. 

> restart:

with(plots):

with(plottools):

with(RealDomain);

#Masses in kg (or pounds!)

m1:=70.0:m2:=25.0:m3:=3.0:

#Equations

solvec:=fsolve({T+N1-m1=0, N2-N1-m2=0,T-N2-m3=0}, {T,N1,N2});

#Above gives the solutions in symbolic or equation form, as well as putting the solutions in a set.  How can the programme distinguish between the various values?

 

# From here is my attempt to form floating point values – to no avail.

NTab:=convert([solvec],table);

N1A:=evalf(solvefor[N1](T+N1-m1*g=0, N2-N1-m2*g=0,T-N2-m3*g=0));

N1B:=convert(N1A, float);

 

#Problem to isolate the solutions in the vector in floating form,

#and also get the correct ones.  NB the solution is a set - not an ordered list.

maxvec:=max(solvec[1],solvec[2],solvec[3]);

#maxvec:=convert(max(solvec[1],solvec[2],solvec[3]), float);

maxvec:=convert(solvec[2], float);

solvec[2];

whattype(solvec[2]);

type(N2,symbol);

type(solvec[2],equation);

N2_fl:=evalf(solvec[2]);

N2_fl:=convert(solvec[2], float);

 

N3:=N2_fl+3;

#Actual true answers

#T:=(m1+m2+m3)/2;

#N1:=(m1-m2-m3)/2;

#N2:=T-m2;

 

OUTPUT:

 

 

Error, (in simpl/max) arguments must be of type algebraic

 

Error, (in simpl/relopsum) invalid terms in sum

I wish to compare five letter words in a list of 5 letter words with a string like "*e*d*".  The asterisks represent unknown letters; the e and d, known letters.  I wish to compare this string with each word in the list and discard any words which do not match.  I would end up with a list of matching words eg ["fends", "sends", . . .]   Is there a string function to compare partial matches?  I've looked at the compare and match commands,  but they don't seem applicable.

   Any suggestions would be most appreciated.

Regards, David 

 

Hi

    The following code displays values of the subscripted variables slf[], a positive integer, and a string variable filler[] which is just a set of spaces depending on how big the corresponding value of slf[] s.  This is to make the printout lined up nicely.  

printf("%s%d%s%d%s%d%s%d%s%d%s%d%s%d%s%d%s%d%s%d\n", filler[1],slf[1],filler[2],slf[2],filler[3],slf[3],filler[4],slf[4],filler[5],slf[5],filler[6],slf[6],filler[7],slf[7],filler[8],slf[8],filler[9],slf[9],filler[10],slf[10]);

   This works fine,but thought there might be a better way.  I tried:

printf("%s%d%s%d%s%d%s%d%s%d%s%d%s%d%s%d%s%d%s%d\n",seq(filler[k],slf[k],k=1..10));

but this came up with an error message.  Is there  a way of doing this more efficiently?

thanks,   David 

 

Hi, I'm searching through a text file looking at individual letters, characters etc.  As part of this I want to detect if the character is the control character for a new paragraph - carriage return, line feed. I believe the ASCII numbers for these are 13, 10 respectively. I'd like to know the code to do this, please.  It's something along the lines: CR:=???:  if c=CR then

where c is a character read from the text file.   ....but what goes in place of ???

Thanks, David

 

I am puzzled at the lack of output in using the solve command.  Bellow is some sample code; the main part being the for k loop with values 1 to 5.  k=1 gives complex solutiions, and k=2 to 5 gives real values.  If the for loop is restricted to from 2 to 5 and the printf statement uncommented, everthing works fine.

I have tried other methods like sols:=fsolve(a*x^2+k*x+c, x, complex);  to little avail. I realize the equation is an easy quadratic & is easy to solve by the usual formula, but I'm interested in how the solve command works.  It seems to perform caculations, without any error messages - which I find frustrating!

The code after the for k from... ...do loop just illustrates examples where solve works - some with complex coefficients - which to my mind makes my problem more enigmatic!  I'm using Maple 7 and am just wondering if the solve command has been made easier to use?

   Any help or comments would be most appreciated.

Kind regards,

  David

 

#Program to investigate the solve function.  Putting k=1 gives complex solutions which halts the program.
> restart:
> interface(imaginaryunit, errorbreak=0, errorcursor=true, labelling=false):
> with(SolveTools):
> a:=1:c:=1:
>

################################
> for k from 1 to 5 do
>   sols:=solve(a*x^2+k*x+c, x):  # assuming x::complex;
>   #printf("k=%d  sols[1]=%5.2f  sols[2]=%5.2f\n", k,eval(sols[1]), eval(sols[2]));
> end do:  #for k

#################################


> printf("End of for loop\n\n");
> sols2:=solve(x^2+I);
> sols2[1];
> sols2[2];
> #sols3:=solve(a*x^3+x^2-I+2);
> solve(z^(I+1)+I,z);
> evalc(op(1,%));  #c=Cartesian
> k:=1:
> sols4:=solve(a*x^2+k*x+c, x):
> #evalc(op(1,%));  #c=Cartesian
> print("Evaluating sols4");
> eval(sols4);
> sols4[1];
> sols4[2];

First 7 8 9 10 11 Page 9 of 11