How can I increase vector size of the output from 7 x 7 double to 30 x 7 double i.e how can I make a for-loop to repeat 30 times?

1 view (last 30 days)
Hi all, How can I increase the size of the output vector of the attached m-file (EulerMethod.m) from 7 x 7 double to 30 x 7 double. I actually need each variable in y0 to have 30 rows, that is, I need the for-loop to repeat 30 times. How can I do that? The file also calls other m-files, namely, Hion.m, C_Bulk.m , odes.m and Parameters.m, which are also attached.
Kind Regards Dursman
  3 Comments
Dursman Mchabe
Dursman Mchabe on 9 Oct 2018
Thanks a lot for the response, I have to quickly read/learn about Pad array or interpolation.
I think I am simply failing to make my loop to repeat 30 times.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 9 Oct 2018
You don't.
You initialized y0 to a 1x7 and then transpose it so that it is 7x1.
In your loop you call odes, which returns a 7x1. You transpose that to 1x7, and multiply by your time step, getting a 1x7.
Now you add the 7x1 y0 to the 1x7. In all releases before r2016b that would be an error. In R2016b and later there is the equivalent of bsxfun, so the results of adding the two with different orientations is 7x7 which is the output size you get.
Perhaps you want to do something more like
y(end+1, :) = y(end, :) + odes().' * Delta
  1 Comment
Dursman Mchabe
Dursman Mchabe on 9 Oct 2018
Thanks a lot for the response, I have to quickly read/learn about Pad array or interpolation.
I think I am simply failing to make my loop to repeat 30 times. I think wanted line 42 to be
y(end+1, :) = y(end, :) + odes().' * Delta
instead of
y = y0 + dydt' * Delt;
Thanks a lot once again Walter.

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!