Subscripted assignment dimension mismatch.

function main
D=1; %L=0;
Pr=1;R=0.1;Sc=1;
xa=0;xb=6;
Lv = [-2.5:0.025:0];
p = [];
for i=1:length(Lv)
L = Lv(i);
fODE = @(x,y) [y(2); y(3); y(2)^2-y(3)*y(1)-1; y(5); -3*Pr*y(1)*y(5)/(3+4*R); y(7); -Sc*y(1)*y(7)];
BCres= @(ya,yb)[ya(1); ya(2)-L-D*ya(3); ya(4)-1; ya(6)-1; yb(2)-1; yb(4);yb(6)];
xint=linspace(xa,xb,101);
solinit=bvpinit(xint,[0 1 0 1 0 1 0]);
sol=bvp4c(fODE,BCres,solinit);
sxint=deval(sol,xint);
%%WE NEED TO PLOT for
S(i,1)=sxint(3,:);
end
figure(1)
plot(Lv,S,'-','Linewidth',1.5);
xlabel('\bf \lambda');
ylabel('\bf C_{f}');
hold on
end
%%While running the code following ERROR occurs:
Subscripted assignment dimension mismatch.
Error in (line 17)
S(i,1)=sxint(3,:);

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 19 Mai 2019

0 Stimmen

function all_sxint = main
D=1; %L=0;
Pr=1; R=0.1; Sc=1;
xa=0;xb=6;
Lv = [-2.5:0.025:0];
nLv = length(Lv);
all_sxint = cell(nLv, 1);
S = zeros(nLv, 7);
for i=1:nLv
L = Lv(i);
fODE = @(x,y) [y(2); y(3); y(2)^2-y(3)*y(1)-1; y(5); -3*Pr*y(1)*y(5)/(3+4*R); y(7); -Sc*y(1)*y(7)];
BCres= @(ya,yb)[ya(1); ya(2)-L-D*ya(3); ya(4)-1; ya(6)-1; yb(2)-1; yb(4);yb(6)];
xint=linspace(xa,xb,101);
solinit=bvpinit(xint,[0 1 0 1 0 1 0]);
sol=bvp4c(fODE,BCres,solinit);
sxint=deval(sol,xint);
all_sxint{i} = sxint;
S(i,:) = sxint(3,:);
end
figure(1)
plot(Lv, S, '-', 'Linewidth', 1.5);
xlabel('\bf \lambda');
ylabel('\bf C_{f}');
legend({'bc1', 'bc2', 'bc3', 'bc4', 'bc5', 'bc6', 'bc7'})
end
Assign the output to a variable so that you can examine all of the time points for all of the Lv values afterwards, as you indicate that you need to be able to do that.

11 Kommentare

MINATI
MINATI am 19 Mai 2019
Still unsolved
Please confirm that what you want to plot is all derivatives for the third time point, not the third derivative for all time points.
function all_sxint = main
D=1; %L=0;
Pr=1; R=0.1; Sc=1;
xa=0;xb=6;
Lv = [-2.5:0.025:0];
nLv = length(Lv);
all_sxint = cell(nLv, 1);
S = zeros(nLv, 7);
for i=1:nLv
L = Lv(i);
fODE = @(x,y) [y(2); y(3); y(2)^2-y(3)*y(1)-1; y(5); -3*Pr*y(1)*y(5)/(3+4*R); y(7); -Sc*y(1)*y(7)];
BCres= @(ya,yb)[ya(1); ya(2)-L-D*ya(3); ya(4)-1; ya(6)-1; yb(2)-1; yb(4);yb(6)];
xint=linspace(xa,xb,101);
solinit=bvpinit(xint,[0 1 0 1 0 1 0]);
sol=bvp4c(fODE,BCres,solinit);
sxint=deval(sol,xint);
all_sxint{i} = sxint;
S(i,:) = sxint(:,3);
end
figure(1)
plot(Lv, S, '-', 'Linewidth', 1.5);
xlabel('\bf \lambda');
ylabel('\bf C_{f}');
legend({'bc1', 'bc2', 'bc3', 'bc4', 'bc5', 'bc6', 'bc7'})
end
MINATI
MINATI am 19 Mai 2019
Its third derivative for all time points.
MINATI
MINATI am 19 Mai 2019
for ref.
We need
Fig. 1 Only solid lines
function main2
D=1; %L=0;
Pr=1; R=0.1; Sc=1;
xa=0; xb=6;
xint=linspace(xa,xb,101);
nxint = length(xint);
Lv = [-2.5:0.025:0];
nLv = length(Lv);
S = zeros(nLv, nxint);
for i=1:nLv
L = Lv(i);
fODE = @(x,y) [y(2); y(3); y(2)^2-y(3)*y(1)-1; y(5); -3*Pr*y(1)*y(5)/(3+4*R); y(7); -Sc*y(1)*y(7)];
BCres = @(ya,yb)[ya(1); ya(2)-L-D*ya(3); ya(4)-1; ya(6)-1; yb(2)-1; yb(4);yb(6)];
solinit = bvpinit(xint,[0 1 0 1 0 1 0]);
sol = bvp4c(fODE,BCres,solinit);
sxint = deval(sol,xint);
S(i,:) = sxint(3,:);
end
figure(1)
plot(Lv, S, '-', 'Linewidth', 1.5);
xlabel('\bf \lambda');
ylabel('\bf C_{f}');
end
However I think you are plotting the wrong thing. Your Y axis is one of the boundary conditions, but the Y axis in the paper is . The paper looks like it is plotting for 3 different δ values, but you are only using one δ value. You asked to plot for all values for all timepoints; in the paper the x axis is and it is not obvious to me that time comes into the plot at all.
It is not obvious to me that you are even calculating the right thing.
MINATI
MINATI am 19 Mai 2019
Bearbeitet: Walter Roberson am 19 Mai 2019
At least for \delta=1 (D=1), the curve should match.
That Rex^(1/2)Cf = sxint(3,1) = f"(0)(in the PAPER), for which straight line will come. But in the paper perhaps they have taken sxint(3,:), which are all values of f"(\eta) of the paper, thats why a curve came.
Walter Roberson
Walter Roberson am 19 Mai 2019
The paper says there is the boundary condition . If your D represents delta, then your D should be appearing in your boundary conditions.
MINATI
MINATI am 19 Mai 2019
In boundary condition
ya(2)-L-D*ya(3)
i.e, D is present
Walter Roberson
Walter Roberson am 19 Mai 2019
I noticed some oddities in the output. I used options to push the permitted mesh points way up, and zoomed in closer. It turns out there is something unusual going on at -2.4648 .
exception.png
Warning: Unable to meet the tolerance without using more than 500000 mesh points.
The last mesh of 292855 points and the solution are available in the output argument.
The maximum residual is 0.204915, while requested accuracy is 0.001.
The above was for Lv = linspace(-2.475, -2.425, 50);
The residual is staying pretty much the same as I increase the number of mesh points and zoom in more closely, which is potentially hinting at a singularity.
Different lines correspond to different xint.
MINATI
MINATI am 20 Mai 2019
No we cant go beyond \lambda = - 2
Walter Roberson
Walter Roberson am 20 Mai 2019
Lv = [-2.5:0.025:0]; is in your existing code

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Matt J
Matt J am 18 Mai 2019
Bearbeitet: Matt J am 18 Mai 2019

0 Stimmen

sxint(3,:) is not a scalar, but the left hand side S(i,1) is a scalar location.

8 Kommentare

MINATI
MINATI am 18 Mai 2019
Bearbeitet: MINATI am 18 Mai 2019
So what to do?
You are looping over several Lv values, running a boundary value problem for each. What would you like plotted from each of those runs?
I suspect you want
S(i,1) = deval(sol, xa, 3);
MINATI
MINATI am 18 Mai 2019
Actually we need for all values of sxint[3] i.e, f "(eta)
sxint(3) is a scalar. It does not make sense to talk about "all values".
There is no eta defined in your question, so I do not know what f''(eta) refers to.
Perhaps you want
S(i,:)=sxint(3,:);
However if you only want the information for the third time point, xint(3), then it is a waste of time to compute sxint for all the time points, and might as well use
sxint = deval(sol, xint(3));
S(i,:) = sxint;
Matt J
Matt J am 18 Mai 2019
@MINATI
So what to do?
You must tell us what the sizes of the left and right hand side of the assigment are intended to be.
MINATI
MINATI am 19 Mai 2019
@Matt J
For all values of sxint(3,:), what changes should be made in S(i,1) OR in Lv
i.e, we need for all values
Walter Roberson
Walter Roberson am 19 Mai 2019
Is there a reason you need to calculate at all of the time points, and then to store data for only the third time point? Is there a particular reason why my suggestion to calculate only at the third time point will not work for you?
MINATI
MINATI am 19 Mai 2019
Yes, Actually I need to validate a previous study with mine but unable. Since they have drawn with all points, I am trying in that way.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Data Exploration finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by