Error:undefined variable in trapezoidal integration

조회 수: 1 (최근 30일)
Yo mama
Yo mama 2020년 4월 28일
댓글: Rena Berman 2020년 5월 14일
Ok this is driving me crazy because it seems so simple. All i need to do is integrate from t=0 and t=3. I have the following function and the comments are what I put into the command window. I need to integrate the ydot vector but once I put it in the function is says that ydot is not defined like what.
  댓글 수: 2
Stephen23
Stephen23 2020년 4월 30일
Original question by Yo mama retrieved from Google Cache:
"Error:undefined variable in trapezoidal integration"
Ok this is driving me crazy because it seems so simple. All i need to do is integrate from t=0 and t=3. I have the following function and the comments are what I put into the command window. I need to integrate the ydot vector but once I put it in the function is says that ydot is not defined like what.
Rena Berman
Rena Berman 2020년 5월 14일
(Answers Dev) Restored edit

댓글을 달려면 로그인하십시오.

답변 (1개)

Brian Iwatake
Brian Iwatake 2020년 4월 28일
If you "clear all", then ydot is not there anymore, right?
  댓글 수: 6
Brian Iwatake
Brian Iwatake 2020년 4월 30일
Hi, I'm still missing something. I didn't have your "ydot", so for my "ydot", I created a simple arbitrary ramp function, ydot = (0 : 2/3 : 100), which is just some big vector - I didn't want to run out of data points.
I = trapezoidal(f, 0, 3, 0.1) was your original function call.
try doubling the step size:
I = trapezoidal(f, 0, 3, 0.2)
For my "ydot" ramp function, the integration result is exactly half. This is not correct.
For your "ydot" data, do you get a reasonable answer for both trapezoidal(f, 0, 3, 0.1) and trapezoidal(f, 0, 3, 0.2)?
Does your result make sense to you?
As you make the step size "h" smaller, your integration result converges to the exact answer. For example, the integration result (usually) shouldn't double every time you cut "h" in half.
Yo mama
Yo mama 2020년 4월 30일
  1. my step size was fixed for the question being asked, the result of my integration was compared to my runge-kutta result for the distance at 3 seconds and I got a percent error of less than one percent - so I think it was spot on, my code only worked when I ran a Sys2ODEsRK4 function as well in another window. My step size needed to be 0.1 explicitely.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Linear Algebra에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by