Evaluate gradient function in the for loop.
古いコメントを表示
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 件のコメント
Sara Boznik
2020 年 8 月 14 日
What happens if you write A(t)?
HN
2020 年 8 月 14 日
Sara Boznik
2020 年 8 月 14 日
It looks like you have only constant.
HN
2020 年 8 月 14 日
回答 (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 件のコメント
USe the vector version, don't call the function for each step. You proceed like this:
t0 = 0 ; t1 = 10 ;
dt = 0.0001 ;
t=t0:dt:t1 ;
x = cos(2*pi*t)
y = sin(2*pi*t)
vx = gradient(x,t)
vy = gradient(y,t)
S=[vx;vy]
HN
2020 年 8 月 14 日
KSSV
2020 年 8 月 14 日
What is F in the solver?
HN
2020 年 8 月 14 日
KSSV
2020 年 8 月 14 日
F is a function, it can be evaluated at once. Loop is not required.
HN
2020 年 8 月 14 日
KSSV
2020 年 8 月 14 日
It is suggested to post the code here..so that if not me others also can help you.
カテゴリ
ヘルプ センター および File Exchange で Mathematics についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!