(Biginner) Code does not work! Please. I need a hand.
古いコメントを表示
I learned some things about this. One, even defining rho and G outside the functions "dp" and " deriv_M" it seems that when MATLAB goes in these functions they do not recognize rho and G so I had to define them inside each function. I just do not know why!!?? Why MATLAB doesnt recognize theses constants?
I used the command global but it didn't work. ( I thought the problem was because these constants were defined just for function gas and then they werent global constants... (didnt work either)
What is the mistery behind it?
Second, I used debugger and this line ("[r1,p] = ode45(@P, Rrange,p_init);") doesnt work. It says variable m not defined. Again, I think that when MATLAB goes inside that function all the variables already estabilished are somehow gone! How do I fix it? How do I make "m" visible to the function dp ??? (That makes the code not run)...
____________________________________________________
function gas
rho = 1;
G = 1;
% Radii for each value of mass
Rrange = [.003 , 10^3] ;
% M(r = 0) = 0 initial value
m0 = 0;
[r, m] = ode45(@M, Rrange,m0);
% P(r = Rmax) = 0
p_init = 0;
subplot(2,1,1)
plot(r,m)
[r1,p] = ode45(@P, Rrange,p_init);
subplot(2,1,1)
plot(r1,p)
function dp = P(r1,p)
G = 1;
rho = 1;
dp = -(rho*G.*m)./r1^2;
function deriv_M = M(r,m)
rho = 1;
G = 1;
deriv_M = 4*(pi*(r.^2))*rho;
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Creating, Deleting, and Querying Graphics Objects についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!