Unable to perform assignment because the left and right sides have a different number of elements. Can anyone help me with this?

조회 수: 1 (최근 30일)
clear all
clc
%boundary condition
x1=[0 0.0069 0.1565 0.3396 0.4666 0.6004 0.7021 0.8286 0.8868 0.9165 0.9561 0.9840 1.0];
P=[57.52 58.2 126 175.3 189.5 224.3 236 250 259 261.11 264.45 266.53 271];
% length(x1)
% length(P)
p=polyfit(x1,P,4);
dpdx=polyder(p);
y10=9.029e-5;
I0=0;
xspan=[1e-5 0.99999];
[x,y]=ode15s(@gibbs,xspan,[y10 I0])
plot(x,y)
function dy= gibbs(x,y)
x1=[0 0.0069 0.1565 0.3396 0.4666 0.6004 0.7021 0.8286 0.8868 0.9165 0.9561 0.9840 1.0];
P=[57.52 58.2 126 175.3 189.5 224.3 236 250 259 261.11 264.45 266.53 271];
p=polyfit(x1,P,4);
dpdx=polyder(p);
dy=zeros(2,1);
P1v=271;
P2v=57.52
Pr=p(1,1)*x^4+p(1,2)*x^3+p(1,3)*x^2+p(1,4)*x+p(1,5);
dP=(dpdx(1,1)*x^3+dpdx(1,2)*x^2+dpdx(1,3)*x+dpdx(1,4));
% dP=-1447.1*x^3+2724.2*x^2-1780.8*x+556.29;
% Pr=-361.764*x^4+908.0529*x^3-890.3941*x^2+556.2994*x+56.2611;
dy(1)=(y.*(1-y)./(y-x)).*(dP)./(Pr) ;
dy(2)=log((y.*Pr)./(x.*P1v))-log((1-y).*Pr./((1-x).*P2v));
end

답변 (1개)

Luna
Luna 2018년 11월 29일
Hi,
Change like below:
dy=zeros(2,2);
dy(:,1)=(y.*(1-y)./(y-x)).*(dP)./(Pr) ;
dy(:,2)=log((y.*Pr)./(x.*P1v))-log((1-y).*Pr./((1-x).*P2v));
  댓글 수: 3
Luna
Luna 2018년 11월 29일
Your code in below gives 2x1 vectors.
(y.*(1-y)./(y-x)).*(dP)./(Pr) % result [11.1169 0]'
log((y.*Pr)./(x.*P1v))-log((1-y).*Pr./((1-x).*P2v)) % result [0.6505 -Inf]'
And you are trying to assign them dy(1) and dy(2) which represents just first and second element of a double array.
Which values you are going to use?

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by