Replacing values inside ODE code
显示 更早的评论
I'm a physics student and I'm working on a code that models rotational velocities of calcite crystals from a second order differential equation. Here is the part of the code I'm having issues with.
for i=1:Nd+1;
d = dmin:deltad:dmax;
for j= 1:NPhi+1;
Phi= Phi_min:Delta_Phi:Phi_max;
[t,x] = ode45(@CPOT,[0 tmax],x0);
velocity = x;
velocity(:,1) = [];
velocity_matrix(i,j) = x(end);
end
end
In this part of the code, I'm extracting the last velocity value and putting it into another matrix called velocity_matrix. For each pass, I want the value of 2 variables (d and Phi) to change, so that I get a final velocity value for each combination of d and phi values. That way, the velocity_matrix can be graphed as a function of d and phi on a contour plot. I'm not sure how to make it so the d and phi values change within the CPOT file for each loop through as I can't write them as matrices inside the CPOT m-file
回答(1 个)
bym
2011-8-6
0 个投票
perhaps you can use anonymous functions as explained here:
类别
在 帮助中心 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!