Evaluate gradient function in the for loop.
조회 수: 4 (최근 30일)
이전 댓글 표시
is a function dependent on time. It is n the function and need to be differentiated to get and the differentiation should pass through the for loop. But for loop picks one value at time t and differentiation failed. Code attached.
function S = Get_Vel(t)
ts=0.0001;
x(t)=cos(2*pi*t)
y(t)=sin(2*pi*t)
vx(t)=gradient(x,ts)
vy(t)=gradient(y,ts)
S=[vx;vy]
end
function A = Compute(t,ts,~,~,~)
S=Get_Vel(t)
end
function solve = solver(F,t0,tf,y0,~)
for t=t0:ts:tf-ts
A =F(t,ts,~,~)
end
solve =A
end
%% MAIN
Result=solver(@Compute,t0,tf,y0,~)
But, since solver used a for loop gradient failed.
Any help is apperciated.
Thank you
댓글 수: 4
답변 (1개)
KSSV
2020년 8월 14일
ts=0.0001;
x(t)=cos(2*pi*t) % index of x is t, it cannot be, it shows error
y(t)=sin(2*pi*t)
vx(t)=gradient(x,ts) % index cannot be fraction and to use gradient you need to have x as vector
vy(t)=gradient(y,ts)
S=[vx;vy]
You may rather use:
ts=0.0001 ;
vx = sin(2*pi*t) ;
vy = cos(2*pi*t) ;
S=[vx;vy]
댓글 수: 10
KSSV
2020년 8월 14일
It is suggested to post the code here..so that if not me others also can help you.
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with Embedded Coder Support Package for STMicroelectronics STM32 Processors에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!