2

I am trying to define some solutions $x_k(t)$ inside a for loop in Maple.

I have tried

enter image description here

but I get an ugly output. I have also tried x[k]:=t-> ... but it makes an even uglier output.

If it wasn't inside a for loop I would have used

x[k] := t -> (...) : 'x[k](t)' = x[k](t) ;

to suppress the output from the assigning and make a nice output in the next line but it seems I cannot suppress only some of the lines inside a for loop?

Jamgreen
  • 809

2 Answers2

3

Suppress all output from the loop using a colon statement terminator on the end do. And then use print inside the loop to prettyprint exact that which you want shown.

for k from 1 to nops(sols) do
  x[k] := unapply(c[k]*exp(lambda[k]*t).v[k],t);
  print('x[k](t)' = x[k](t));
end do:
acer
  • 5,293
  • Thank you! But print('x[k](t)' = outputs $x_k(t) =$ instead of replacing $k$ with $1$ and $2$, resp. – Jamgreen Sep 13 '15 at 08:03
  • You are free to use print( subs(_K=k,'x[_K](t)') = ...) or build up that lhs howsoever you wish. I see that you''re now using . to keep Vector coefficients from being multiplied through the Vector (as I suggested as Answer to an earlier question of yours). But it's curious that you do not vote up or accept any of my answers to your questions, even when they clearly server to get the result. – acer Sep 14 '15 at 00:54
1

to suppress the output from the assigning and make a nice output in the next line but it you can use the tool step

> for k from 1 to nops (sols) steps 2 do
    x[k]=...

You will be able to suppress some of the lines inside of the loop.

  • I want to suppress one of the lines inside the for loop, not some of the elements in sols – Jamgreen Sep 11 '15 at 07:34
  • I see, you should had specified it in your question. I'm asking around if ever somedy knows it but why don't you try to cut off your loop in two? – Revolucion for Monica Sep 11 '15 at 07:37
  • I could avoid using a loop; however, I want the code to handle $n$ number of solutions, but it seems I have to give up on creating a such generic solution – Jamgreen Sep 11 '15 at 08:45