I'm trying to solve a quadratic equation by varying a variable multiple times
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi, I'm very new to MATLAB so please forgive my question.
So I'm trying solve the quadratic equation to find yps by varying the value of pHs . We should expect to get 2 values of yps for each value of pHs.
This is the error matlab gives me. Subscripted assignment dimension mismatch.
pH =[5450 7000 9000 ];
for j=1:length(pHs)
ff(j)= yps/(1-yps) - alphas*(( xos - (pLs/pHs(j)) * yps) / ((1-xos)-(pLs/pHs(j))*(1-yps))) ;
yp(j) = solve(ff(j),yps) ; %error is in this line
ypp(j) = eval(yp(j)) ;
end
댓글 수: 0
채택된 답변
Sulaymon Eshkabilov
2019년 5월 26일
Hi,
Here is the corrected code:
% Since you are trying to solve your system symbolically then you'd need to
% assign symbolic variables with:
syms yps pLs alphas xos
% Or you can plug in the numerical values for: [pLs, alphas, xos], then you
% will get the numerical solutions for ypp for each value of pHs.
% Otherwise, you get now the solutions in a symbolic expressions in terms of: [alphas, xos, pLs].
pHs =[5450 7000 9000 ];
for jj=1:length(pHs)
ff= yps/(1-yps) - alphas*(( xos - (pLs/pHs(jj)) * yps) / ((1-xos)-(pLs/pHs(jj))*(1-yps))) ;
yp(:, jj) = solve(ff,yps) ;
ypp(:, jj) = eval(yp(:,jj)) ;
end
Note that if you have the numerical values of [pLs, alphas, xos], then you'd need to assign them before for loop or substitute in the equation.
Good luck.
댓글 수: 2
Sulaymon Eshkabilov
2019년 5월 26일
Hi Alfaisal,
Indeed, you have undersood correctly that in this case, your soultions have to be in a matrix form but not in a vector form. Good luck.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!