Undefined Variable Error in Function
古いコメントを表示
For my homework we have to plot a second order differential equation. I believe I have the basic structure of how to do this down but I keep getting and error about one of my variables.
I keep getting an error saying that x is not defined, however I can't seem to find a place where I would define it as the second order equation is acceleration and in terms of velocity. Is there a place where I can define x without messing up the rest of my code or a way to get MATLAB to ignore it.
v0 = 10; %initial velocity
theta = 45; % degrees
m = 1; %kg
x0 = 0; %Initial x
y0 = 0; % Initial y
g = 9.8; %gravity
tspan = [0 ; .0001 ; .3]; %seconds
[t,x] = ode45(@f,tspan,x0);
function fix = f(t,x)
x = X(1);
v = X(2);
c = 0;
fix = [ v ; -c*v*cos(theta)/1*(sqrt(v*cos(theta)+v*sin(theta)))^(p-1) ];
end
3 件のコメント
Walter Roberson
2020 年 2 月 25 日
What is y0? Why do you assign to it but not use it?
You pass x0 as the only initialization for the boundary conditions. As your x0 is a scalar you are informing matlab that you have a system with one state. But your code attempts to access two states.
Sarah Peterson
2020 年 2 月 25 日
Pravin Jagtap
2020 年 2 月 28 日
Hello Sarah,
Can you let us know which equation you want to solve? (Also specify the initial and boundary conditions) You mentioned the solution of the governing equation. I can see that you are dealing with projectile motion.
回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Numerical Integration and Differential Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
