Varying Variables within a Function
古いコメントを表示
The code that I currently have works perfectly for the variables that I have already assigned as constants.
%Setting the time interval in seconds
tspan = [0 20];
%Using the ODE Function
[t,x] = ode45(@Cart,tspan,[5 0]);
%Plotting the graph with a legend
plot(t,x(:,1),'DisplayName','Position'); hold on;
plot(t,x(:,2),'DisplayName','Velocity');
xlabel('Time'); ylabel('X-Values');
legend
%Writing out the function
function output = Cart(t,x)
m=2; %mass
b = 1.3; %damping
k = 20; %spring constant
x1prime = x(2);
x2prime = (-k*x(1)-b*x(2))/m;
output = [x1prime; x2prime];
end
Thank you for your time and help!
3 件のコメント
Walter Roberson
2020 年 11 月 14 日
Sam Zavala:
If you feel that your question is unclear, then since you are the author of the question, instead of flagging the question and hoping that a moderator will kindly take the time to figure out what you really meant and re-write the question to be better explained, then you should be spending the time to explain the question better yourself. You are the person who knows best what you need; you should not expect that someone else will spend the time making your question more clear.
Sam Zavala
2020 年 11 月 14 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で General Applications についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!