Evaluate gradient function in the for loop.
8 次查看(过去 30 天)
显示 更早的评论
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/346047/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/346044/image.png)
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 LMI Solvers 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!