Hello 조 성호,
제 모국어는 한국어가 아니라서, 이 질문에 영어로 답변하려고 합니다. 이해해주셔서 감사합니다.
I understand that you are getting an error of “unrecognised variable” while running your code. I tried reproducing the error through your code. I found a workaround for you which you can try.
- Instead of 2 functions ‘comp’ and ‘chem’ in a single file, try having function ‘comp’ in a separate file and call the file using ‘type’ command.
type comp.m
- Inside ‘comp.m’ function file, omit using ‘end’ statement.
- In the parent script file, omit using function ‘chem’ as it is unused and not being called anywhere in your code
type comp.m
fun = @comp;
x0 = [10,10,10,10,10,10];
x= fsolve(fun,x0)
CO = 100-x(2)+x(3)-x(4)-2*x(5)+2*x(6)
CO2 = 100-x(1)-x(3)+x(5)-x(6)
H2 = 1467-4*x(1)-3*x(2)-x(3)-x(4)+2*x(6)
CH4 = x(1)+x(2)-x(6)
H2O = 2*x(1)+x(2)+x(3)+x(4)
C = x(4)+x(5)
For more information, refer to the MATLAB documentation of ‘fsolve’ function:
I hope this helps in your query!