substituting function variable in function handle

13 views (last 30 days)
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 Comments
Bathala Teja
Bathala Teja on 14 Sep 2021
sir can you please rewite my script with your changes?
iam really confused sir please help me out

Sign in to comment.

Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!