printing values into a table
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Walter Roberson
am 18 Okt. 2015
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 Kommentare
Walter Roberson
am 19 Okt. 2015
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?
Siehe auch
Kategorien
Mehr zu Foundation and Custom Domains finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!