substituting function variable in function handle

조회 수: 13 (최근 30일)
Bathala Teja
Bathala Teja 2021년 9월 14일
댓글: Bathala Teja 2021년 9월 14일
i want to substitute y(5) in place of theta and poceed for the ode calculations.
Here is my script
syms theta
A0 = cos(theta).*[1 5 6; 2 9 3; 1 4 5];
A =[A0 zeros(3, 2);
zeros(2, 3) [1 0; 0 1]]
B = tan(2*theta).*[8 5 1 0 0; 1 1 6 0 0; 2 4 7 0 0; 0 0 0 0 0; 0 0 0 0 0]
C = (cos(2*theta)+2).*[8 5 1; 0 1 6; 2 4 7];
myfun = @(t,y)scriptname(t,y,A,B,C);
% dummy values for tspan and y0
tspan = [0 1];
y0 = zeros(1, 5);
An = matlabFunction(subs(A, y(5)))
Bn = matlabFunction(subs(B, y(5)))
Cn = matlabFunction(subs(C, y(5)))
sol = ode45(myfun,tspan,y0);
h = figure;
plot(sol.x,sol.y(i,:));
function dydt = scriptname(t,y,An,Bn,Cn)
inertia = 0.05;
Wr = 2*pi*50;
p =2;
% Cn = double(subs(C,y(5)))
for i=1:3
I(i,1)=y(i);
end
I
Te = 1/2*p*I'*Cn*I
if t<0.75
Tl=0;
else
Tl=7.31;
end
V = [1.4142*400/sqrt(3)*cos(Wr*t);
1.4142*400/sqrt(3)*cos(Wr*t+2.*pi/3.);
1.4142*400/sqrt(3)*cos(Wr*t-2.*pi/3.);
(Te-Tl)/inertia;
y(4)]
% An = double(subs(A,y(5)))
% Bn = double(subs(B,y(5)))
dydt = An\V-(Bn*y);
end
It is showing the error of "unrecognized function or variable y".
  댓글 수: 3
Bathala Teja
Bathala Teja 2021년 9월 14일
sir can you please rewite my script with your changes?
iam really confused sir please help me out
Bathala Teja
Bathala Teja 2021년 9월 14일
hello
anything edited??

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

답변 (0개)

카테고리

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

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by