Why does this for loop fail?

2 次查看(过去 30 天)
cmcelm
cmcelm 2019-11-10
评论: cmcelm 2019-11-10
I'm trying to create a for loop that will assign a solved element of a function to a blank vector for every value of a given vector. However, when I try to run this code it gives "Error: Assignment has more non-singleton rhs dimensions than non-singleton subscripts" and stops on about the 44th value or so. I made the two vectors the same dimensions, so why am I getting dimensional errors?
syms T V
Ttp = 89.4
% function from earlier
PRfxn = matlabFunction(PREos)
% will use later
dPdV = diff(PREos, V)
dPdT = diff(PREos, T)
CpMinusCv = (-T*(dPdT)^2)/dPdV
CpCvfxn = matlabFunction(CpMinusCv)
% trying to get my T and V for a given P == Pc (variable defined earlier) variable Tc is also defined earlier
Trange = [Ttp:10:2.5*Tc]
Vrange = zeros(1, length(Trange))
i = 1;
for T = Trange
Vrange(1, i) = vpasolve(PRfxn(Trange(1, i), V) == Pc, V, [0 inf])
i = i+1;
end

采纳的回答

Stephan
Stephan 2019-11-10
编辑:Stephan 2019-11-10
vpasolve may find more than one solution. Try to save your results in a cell array:
...
Vrange = cell(1, length(Trange))
...
Vrange{i} = vpasolve(PRfxn(Trange(1, i), V) == Pc, V, [0 inf])
  1 个评论
cmcelm
cmcelm 2019-11-10
Thanks! I tested vpasolve and found that it was returning two roots. I'll fix the dimensions on my vpasolve because I only need one root.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品


版本

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by