For homework questions, the policy is to see some work from the poster. Since you don't know programming, I've outlined what the code is doing, beyond the simple operations (+, -, /, *, ^), to get you started. I think you should be able to implement the models with this information, and I'd be happy to confirm your own answers.
So the best way to figure out what any line of code means, in any language, is to type it and see what happens. To help you get started with programming in MATLAB:
Any text following a % (on the same line) is a comment: it does nothing in the program, and is only there for you to write notes to yourself.
The first two sections, Time-Related Constants and Simulation Constants, are just setting variables. It's like saying x = 3, so that later on you can do other operations with x.
The semicolon at the end of a line (in MATLAB) suppresses the output of the line. See what happens if you type x = 3; versus x = 3 at the command prompt.
In iteration constants, length is just a function that tells you the length of the vector. X_rna_0 was previously initialized to go from 0 to 1.4 in steps of 0.2: the syntax is vector_name = start:step:end.
The simulation variables section is creating xyz-matrices, with all values initialized to zero. The length in x is xr_max, and so on. The idea is that, later on, at each step in Euler's method and each value of xr_max and xp_max, you'll save the value of X_rna.
The initial conditions are being set using meshgrid, which is best explained here. The : means all of the rows/columns, corresponding to position: say you had a 3 x 3 matrix called apple. apple[:,1] gives you all the first column (1) of all three rows. apple[1,:] gives you the first row (1) of all three columns. The .' means that the matrix is being transposed: again, the best way to see what's going on is to create a matrix of your own, perform the operation, and see if what you get is what you thought it would be.
For loops, you can read about here, for a start. I do not think understanding this loop requires more information than that page.
Dot before ^2 means that each element of the matrix is being squared; you are not multiplying the matrix by itself.
That should decipher most of the code for you. If you have further questions, feel free to comment here.
EDIT: Question 2 asks you to make a plot. A plot of y vs. x would be made by typing plot(x,y)
Also, help on a particular MATLAB function can be accessed by typing help name_of_function.
No comments:
Post a Comment