Assignment has more non-singleton rhs dimensions than non-singleton subscripts

function [ Ts1] = ref1()
tf=30000;
h=1;
tf1=0:h:tf;
% Ts1
T_ref1=10*ones(30001,1);
for i=6001:12001
T_ref1(i)= (13/6000)*(i-1)-3;
end
for i=12002:18001
T_ref1(i)=23;
end
for i=18002:24001
T_ref1(i)=-(13/6000)*(i-1)+62;
end
% plot(tf1',T_ref1);
Ts1 = [tf1' T_ref1];
return
==
function [ Ts2] = ref2()
tf=30000;
h=1;
tf2=0:h:tf;
T_ref2=10*ones(30001,1);
for i=6001:12001
T_ref2(i)= (1/500)*(i-1)-2;
end
for i=12002:18001
T_ref2(i)=22;
end
for i=18002:24001
T_ref2(i) = -(1/500)*(i-1)+58;
end
% plot(tf2',T_ref2);
Ts2 = [tf2' T_ref2];
return
Ta=5;
dx(1,1) = 0.001*(-x(1)+Ta+0.01*x(3));
dx(2,1) = 0.001*(-x(2)+Ta+0.01*x(4));
Ts1=ref1;
Ts2=ref2;
f1 = (x(1)-Ts1)-ep*(1/x(3));
f2 = (x(2)-Ts2)-ep*(1/x(4));
f3 = -ep*(1/x(5));
dx(3,1) = G*(f3-f1);
dx(4,1) = G*(f3-f2);
dx(5,1) = G*(f1-f3 + f2-f3);
===
Assignment has more non-singleton rhs dimensions than
non-singleton subscripts
Error in xODE_v1 (line 26)
dx(3,1) = G*(f3-f1);
Could you please give me your advice to fix this error? Thank you so much.
Best regards,
Peter.

 Accepted Answer

You have
f1 = (x(1)-Ts1)-ep*(1/x(3));
Ts1 is a vector so f1 is a vector
You then have
dx(3,1) = G*(f3-f1);
f1 is a vector so the right hand side is a vector. You are trying to store that entire vector into the single location dx(3,1)

2 Comments

Dear Prof. Walter Roberson, I am so sorry for my late response. Your advice is very useful for me to dealing with some problem. Actually, I still cannot solve my problem. I may thing my formulation have something wrong, so I cannot use that method, it is not only the code command. Again thank you very much for your time. Hope I will have opportunity to receive more your suggestion in near future. Best regards, Peter.
Your ref2 code gives me the impression that you are trying to use one of the ode* routines, but if you are calling ref2 from one of the ode* routines then it would need to take two inputs.
The purpose of your code is not documented and you have no comments.

Sign in to comment.

More Answers (0)

Categories

Find more on Fractals in Help Center and File Exchange

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!