printing values into a table
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello Folks,
I am trying to create a code that I will solve a system of nonlinear equations and print the solutions into a table in a .doc file. The equations are functions of Theta. I want to print the solution to the system of equations for theta = 0:30:360.
I created the following code:
function F = Solution(x)
Lab = .1;
Lbc = .6;
Lcd = .3;
Lad = .4;
fid = fopen('Solution.doc','w');
fprintf(fid,'theta x1 x2 x3 x4 \n');
fprintf(fid,'_______________________________________________________\n')
n=0;
for theta=0:30:360
n=n+1;
rabx = Lab*cosd(theta)
raby = Lab*sind(theta)
F = [
(x(1))^2 + (x(2)^2)- Lbc^2;
(x(3))^2 + (x(4))^2 - Lcd^2;
raby + x(2) + x(4);
rabx + x(1) + x(3) - Lad];
tab=[theta;x(1);x(2);x(3);x(4)];
fprintf(fid,'%5d %9.f %8.3f %8.3f %12.4f %12.4f\n', tab);
end
end
When I try to run the code, using fsolve, I get the following error : Too many open files. Close files to prevent MATLAB instability.
Caused by: Unknown exception
How can I fix this?
Thanks in advance.
댓글 수: 0
답변 (1개)
Walter Roberson
2015년 10월 18일
You have
fid = fopen('Solution.doc','w');
but no-where in your code do you have
fclose(fid)
so you are leaving the file open :(
댓글 수: 2
Walter Roberson
2015년 10월 19일
The code is doing what you asked it to do, which is to print out each theta value together with the unmodified x(1), x(2), x(3), x(4) values.
Perhaps you wanted to print out the F values instead of the x values?
참고 항목
카테고리
Help Center 및 File Exchange에서 Foundation and Custom Domains에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!