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.

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 日

0 投票

If you "clear all", then ydot is not there anymore, right?

6 件のコメント

Yo mama
Yo mama 2020 年 4 月 28 日
I am the dumbest human alive lol
Brian Iwatake
Brian Iwatake 2020 年 4 月 29 日
No, you're not. I have done worse. Thanks for introducing me to <f = @(x) g(x)> notation.
Now, I think you have a logic error. <f = @(x) ydot> does not make sense to me because you have defined ydot to be a constant row vector with no dependence on x, I think.
In your "trapezoidal" function, <F = Fun(x)> will always return "ydot", no matter what "x" is, if I am interpreting your code correctly. Please post what you have figured out.
Yo mama
Yo mama 2020 年 4 月 30 日
so the ydot vector I got was the result after evaluating 2 ODE's using 4th Order Runge Rutta method. Hence it I needed to plot a distance line and a velocity line. So I got all those y dot values from that. My x vector was technically time it was 0 secons to 3 seconds with step size 0.1, and I needed to evaluate what the distance was at 3 seconds. So I was basically integrating a vector with those terms of integration. Honestly, I was using a program we had in the book. I mean I think that makes sense.
Yo mama
Yo mama 2020 年 4 月 30 日
Like It was a user defined function so like in the command window id put f=@(x)(ydot);
%disp('Value')
%I=trapezoidal(f,0,3,0.1)
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.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

質問済み:

2020 年 4 月 28 日

コメント済み:

2020 年 5 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by