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!
