473,382 Members | 1,389 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

i was 2asked to develop a project to make mathematical opertaion on matrix but i was

i was 2asked to develop a project to make mathematical opertaion on matrix but i was forced in the input method that would be [1 2;3 4] for 2x2 matrix and [1 2 3;4 5 6;7 8 9] for 3x3 matrix and i want to know how to take the float numbers from string to array without taking semicolon and spaces [ and]

https://cdn.fbsbx.com/hphotos-xfp1/v...=553D30DE&dl=1
Apr 25 '15 #1
13 1696
weaknessforcats
9,208 Expert Mod 8TB
If you need input like [1 2;3 4] then why do you think you need a string?

I mean, what the user sees is [1 2;3 4] and that doesn't mean using a string.

So display a [
scanf two floats
Display a ;
scanf two more floats
Display a ]

If this program is about matrix mathematics, then get the mathematics working first and then go back and work on the user input format. You can spend a lot of time formatting user input so I would take an easy way out until you have more experience.
Apr 25 '15 #2
the project description is attached in the link it is a project asked from me in faculty of engineering while i have recently studied c++
Apr 25 '15 #3
zmbd
5,501 Expert Mod 4TB
esslam200 - the project description is attached in the link it is a project asked from me in faculty of engineering while i have recently studied c++
Two things here:
1) It is preferable to have a clear and complete description as the post, not as an attachment, especially an attachment stored at a third part site. One little opps, or deletion and the thread becomes worthless.

Along that same line, many of our experts help from within secured network settings (ie work) and the IT has restricted access to offsite storage. This is to protect the company from all sorts of nasties. :)

2) We don't do homework assignments. It's not fair to you nor other students to have the experts do the work for you.
If you want help on a homework assignment, then post your work first - many of us may provide direction in such cases depending on the amount of effort made by the student.
Apr 25 '15 #4
Luuk
1,047 Expert 1GB
hmmmz, and my post was just stating point 2 in the last answer.....

But it got 'moderated'.... ;)


But I more helpful answer from /me would be:
I know of a function called 'split'. I exists in PHP and in C#

The must be some equivalent for it in C++

But did your teacher not tell you a thing? Some stuff on how to solve this assignment MUST have been explained in the lessons you've got.... ;)
Apr 25 '15 #5
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <string>
  3. #include <cstdlib>
  4. #include <sstream>
  5. #include<string>
  6. #include<math.h>
  7. using namespace std;
  8. int main ()
  9. {    string a,b,op;
  10. float x[100][100],y[100][100],c,d;
  11. int nspace1=0,nsemi1=1,nsemi2=1,nspace2=0,n1,n2;
  12.  
  13. getline(cin,a);
  14. getline(cin,op);
  15. getline(cin,b);
  16. n1=a.length();
  17. for (int i=0;i<n1;i++)
  18. {if (a[i]==';')
  19. nsemi1++;
  20. }
  21. n2=b.length();
  22. for (int i=0;i<n2;i++)
  23. {if (b[i]==';')
  24. nsemi2++;
  25. }
  26. n1=a.length();
  27. for (int i=0;i<n1;i++)
  28. {if (a[i]==' ')
  29. {nspace1++;}
  30.  
  31. }
  32. nspace1=(nspace1/nsemi1)+1;
  33. for (int i=0;i<n2;i++)
  34. {if (b[i]==' ')
  35. {nspace2++;}
  36.  
  37. }
  38. nspace2=(nspace2/nsemi2)+1;
  39.  
  40. for (int i=0;i<nsemi1;i++)
  41.  
  42. {for(int j=0;j<nspace1;j++){x[i][j]=atof(a.c_str());}}
  43. for (int i=0;i<nsemi1;i++)
  44. {for(int j=0;j<nspace1;j++){cout<<x[i][j]<<" ";}}
  45. system ("PAUSE");
  46.  
  47. }
Apr 25 '15 #6
now i delivered here but i don,t have idea how to make Inverse or power is not there any idea?




Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <string>
  3. #include <cstdlib>
  4. #include <sstream>
  5. #include<string>
  6. #include<math.h>
  7. using namespace std;
  8. int main ()
  9. {    string a,b,op,c,d,e,f=" ",r,p;
  10. float x[100][100],y[100][100],z[100][100];
  11. float nspace1=0,nsemi1=1,nsemi2=1,nspace2=0,n1,n2,k,v;
  12.  
  13.  
  14. getline(cin,a);
  15. if(v==(int)v)
  16. {getline(cin,op);
  17. }
  18. else 
  19. {cout<<"ERROR";
  20. }
  21.  
  22.  
  23. if(op=="+"||op=="-"||op=="*"||op=="^"||op=="T"||op=="D"||op=="I"||op=="/")
  24. {
  25. getline(cin,b);}
  26. else
  27. {cout<<"ERROR";
  28. }
  29.  
  30.  
  31. n1=a.length();
  32. for (int i=0;i<n1;i++)
  33. {if (a[i]==';')
  34. nsemi1++;
  35. }
  36. n2=b.length();
  37. for (int i=0;i<n2;i++)
  38. {if (b[i]==';')
  39. nsemi2++;
  40. }
  41. n1=a.length();
  42. for (int i=0;i<n1;i++)
  43. {if (a[i]==' ')
  44. {nspace1++;}
  45.  
  46. }
  47. nspace1=(nspace1/nsemi1)+1;
  48. v=nspace1;
  49.  
  50. for (int i=0;i<n2;i++)
  51. {if (b[i]==' ')
  52. {nspace2++;}
  53.  
  54. }
  55. nspace2=(nspace2/nsemi2)+1;
  56. c=a.substr(1,n1-2);
  57. d=b.substr(1,n2-2);
  58. c=c+";";
  59. d=d+";";
  60.     /*Removing rubbish from string1*/
  61.     for(int i=0;i<nsemi1;i++)
  62.     {
  63.         e=c.insert(c.find(';')," ");
  64.         e=c.erase(c.find(';'),1);
  65.  
  66.  
  67.  
  68.     }
  69.     /*Removing rubbish in string 2*/
  70.     for(int i=0;i<nsemi2;i++)
  71.     {
  72.         f=d.insert(d.find(';')," ");
  73.         f=d.erase(d.find(';'),1);
  74.     }
  75.  
  76.     /*filling array1 from str1*/
  77.  
  78.     for(int i=0;i<nsemi1;i++)
  79. {for (int j=0;j<nspace1;j++)
  80. {r=e.substr(0,e.find(' '));
  81. x[i][j]=atof(r.c_str());
  82. e=e.erase(0,e.find(' ')+1);
  83.  
  84. }
  85. }
  86.     /*filling array2 from str2*/
  87.     for(int i=0;i<nsemi2;i++)
  88. {for (int j=0;j<nspace2;j++)
  89. {p=f.substr(0,f.find(' '));
  90. y[i][j]=atof(p.c_str());
  91. f=f.erase(0,f.find(' ')+1);
  92.  
  93. }
  94. }
  95.  
  96.  
  97.  
  98.     /*addition*/
  99. if(op=="+")
  100. {if(nsemi1==nsemi2&&nspace1==nspace2)
  101. {
  102. cout<<"[";
  103. for(int i=0;i<nsemi1;i++)
  104.     {for(int j=0;j<nspace1;j++)
  105.     {z[i][j]=x[i][j]+y[i][j];
  106.     cout<<z[i][j]<<" ";
  107.     }cout<<";"    ;
  108.     }
  109.     cout<<"]";}
  110.     else {cout<<"ERROR";}
  111.     }
  112.  
  113. /*substraction*/
  114. if(op=="-")
  115. {    if(nsemi1==nsemi2&&nspace1==nspace2)
  116. {cout<<"[";
  117.     for(int i=0;i<nsemi1;i++)
  118.     {for(int j=0;j<nspace1;j++)
  119.     {z[i][j]=x[i][j]-y[i][j];
  120. cout<<z[i][j]<<" ";
  121.     }
  122. cout<<";"    ;
  123.     }
  124.     cout<<"]";
  125. }
  126. else {cout<<"ERROR";}
  127. }
  128.  
  129. /* multiplying */
  130.  
  131. if(op=="*")
  132. {if(nspace1==nsemi2)
  133.  
  134.  
  135.  
  136. {
  137. cout<<"[";
  138. for(int i=0;i<nsemi1;i++)
  139. {
  140. for(int j=0;j<nspace2;j++)
  141. {
  142. z[i][j]=0;
  143. for(int q=0;q<nsemi2;q++)
  144. {
  145. z[i][j]=z[i][j]+x[i][q]*y[q][j];
  146. }
  147. }
  148. }
  149.  
  150. for(int i=0;i<nsemi1;i++)
  151. {
  152. for(int j=0;j<nspace2;j++)
  153. {
  154.  cout<<z[i][j]<<" ";
  155. }
  156.  cout<<";"    ;
  157. }
  158. cout<<"]";
  159.  
  160. }
  161. else{cout<<"ERROR";
  162. }
  163. }
  164.  
  165.  
  166.  
  167. if(op=="T")
  168. {/* Transpose*/
  169. for(int i=0;i<nsemi1;i++)
  170. {for(int j=0;j<nspace1;j++)
  171. {z[i][j]=x[i][j];
  172. cout<<z[j][i]<<" ";
  173. }
  174. cout<<";"    ;
  175. }
  176. cout<<"]";
  177. }
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185. }
Apr 27 '15 #7
weaknessforcats
9,208 Expert Mod 8TB
You have already worked out multiplication. But it is not a function you can call.

Make a function out of it:

Expand|Select|Wrap|Line Numbers
  1. int Multiply(float* a, float* b, float*c); 
So I pass in the addresses of two matrices (a and b) and get the product matrix (c).

Then call this function in your to-be-written power function:

Expand|Select|Wrap|Line Numbers
  1. int Power(float* a, float* b, float*c, int exp); 
Inside this function you run a loop from 0 to <exp and inside the loop you call the Multiply function. The product matrix (c) replaces one of the other matrices before the loop cycles and the Multiply function is called again.

Inverse power is just 1/matrix where matrix is the power result from the above function. You have already worked out division so you might make a function out of it also so you can use it here.
Apr 28 '15 #8
can u make this function for me
Apr 28 '15 #9
weaknessforcats
9,208 Expert Mod 8TB
I can't do that because if I did you still would not know how to do this. The basic blocks in C++ are functions and unless you learn how to write functions, you won't be able to write programs.

Read this: http://bytes.com/topic/c/insights/77...rrays-revealed

This article shows how to use arrays friom inside a function.
Apr 28 '15 #10
but i didn,t take pointers in my course belive me Iam beginner and i find complexity to understand this article
Apr 29 '15 #11
I make the inverse and power but there are logical error that i can,t find please can u find it
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <string>
  3. #include <cstdlib>
  4. #include <sstream>
  5. #include<string>
  6. #include<math.h>
  7. using namespace std;
  8. int main ()
  9. {    string a,b,op,c,d,e,f=" ",r,p;
  10. float x[100][100],y[100][100],z[100][100];
  11. float nspace1=0,nsemi1=1,nsemi2=1,nspace2=0,n1,n2,v;
  12. int pow,nn,k;
  13.  
  14. getline(cin,a);
  15. if(v==(int)v)
  16. {getline(cin,op);
  17. }
  18. else 
  19. {cout<<"ERROR";
  20. }
  21.  
  22. if(op=="+"||op=="-"||op=="*"||op=="/")
  23. {
  24. getline(cin,b);
  25. n2=b.length();
  26. for (int i=0;i<n2;i++)
  27. {if (b[i]==';')
  28. nsemi2++;
  29. }
  30. for (int i=0;i<n2;i++)
  31. {if (b[i]==' ')
  32. {nspace2++;}
  33. }
  34. nspace2=(nspace2/nsemi2)+1;
  35. d=b.substr(1,n2-2);
  36. d=d+";";
  37. /*Removing rubbish in string 2*/
  38.     for(int i=0;i<nsemi2;i++)
  39.     {
  40.         f=d.insert(d.find(';')," ");
  41.         f=d.erase(d.find(';'),1);
  42.     }
  43.         /*filling array2 from str2*/
  44.     for(int i=0;i<nsemi2;i++)
  45. {for (int j=0;j<nspace2;j++)
  46. {p=f.substr(0,f.find(' '));
  47. y[i][j]=atof(p.c_str());
  48. f=f.erase(0,f.find(' ')+1);
  49.  
  50. }
  51. }
  52. }
  53.  
  54. n1=a.length();
  55. for (int i=0;i<n1;i++)
  56. {if (a[i]==';')
  57. nsemi1++;
  58. }
  59.  
  60. n1=a.length();
  61. for (int i=0;i<n1;i++)
  62. {if (a[i]==' ')
  63. {nspace1++;}
  64.  
  65. }
  66. nspace1=(nspace1/nsemi1)+1;
  67.  
  68. v=nspace1;
  69.  
  70.  
  71. c=a.substr(1,n1-2);
  72.  
  73. c=c+";";
  74.  
  75.     /*Removing rubbish from string1*/
  76.     for(int i=0;i<nsemi1;i++)
  77.     {
  78.         e=c.insert(c.find(';')," ");
  79.         e=c.erase(c.find(';'),1);
  80.  
  81.     }
  82.  
  83.     /*filling array1 from str1*/
  84.  
  85.     for(int i=0;i<nsemi1;i++)
  86. {for (int j=0;j<nspace1;j++)
  87. {r=e.substr(0,e.find(' '));
  88. x[i][j]=atof(r.c_str());
  89. e=e.erase(0,e.find(' ')+1);
  90.  
  91. }
  92. }
  93.  
  94.  
  95.     /*addition*/
  96. if(op=="+")
  97. {if(nsemi1==nsemi2&&nspace1==nspace2)
  98. {
  99. cout<<"[";
  100. for(int i=0;i<nsemi1;i++)
  101.     {for(int j=0;j<nspace1;j++)
  102.     {z[i][j]=x[i][j]+y[i][j];
  103.     cout<<z[i][j]<<" ";
  104.     }cout<<";"    ;
  105.     }
  106.     cout<<"]";}
  107.     else {cout<<"ERROR";}
  108.     }
  109.  
  110. /*substraction*/
  111. if(op=="-")
  112. {    if(nsemi1==nsemi2&&nspace1==nspace2)
  113. {cout<<"[";
  114.     for(int i=0;i<nsemi1;i++)
  115.     {for(int j=0;j<nspace1;j++)
  116.     {z[i][j]=x[i][j]-y[i][j];
  117. cout<<z[i][j]<<" ";
  118.     }
  119. cout<<";"    ;
  120.     }
  121.     cout<<"]";
  122. }
  123. else {cout<<"ERROR";}
  124. }
  125.  
  126. /* multiplying */
  127.  
  128. if(op=="*")
  129. {if(nspace1==nsemi2)
  130.  
  131.  
  132. {
  133. cout<<"[";
  134. for(int i=0;i<nsemi1;i++)
  135. {
  136. for(int j=0;j<nspace2;j++)
  137. {
  138. z[i][j]=0;
  139. for(int q=0;q<nsemi2;q++)
  140. {
  141. z[i][j]=z[i][j]+x[i][q]*y[q][j];
  142. }
  143. }
  144. }
  145.  
  146. for(int i=0;i<nsemi1;i++)
  147. {
  148. for(int j=0;j<nspace2;j++)
  149. {
  150.  cout<<z[i][j]<<" ";
  151. }
  152.  cout<<";"    ;
  153. }
  154. cout<<"]";
  155.  
  156. }
  157. else{cout<<"ERROR";
  158. }
  159. }
  160.  
  161.  
  162. /* Transpose*/
  163. if(op=="T")
  164. {
  165. if(v==(int)v)
  166. {
  167. cout<<"[";
  168. for(int i=0;i<nspace1;i++)
  169. {for(int j=0;j<nsemi1;j++)
  170. {
  171. cout<<x[j][i]<<" ";
  172. }
  173. cout<<";"    ;
  174. }
  175. cout<<"]";
  176. }
  177. else{cout<<"ERROR";
  178. }
  179. }
  180. /*Determinent*/
  181. if(op=="D")
  182. {
  183. if(nsemi1==nspace1)
  184.  
  185. {if(nsemi1==2)
  186. {cout<<(x[0][0]*x[1][1]-x[0][1]*x[1][0]);}
  187.  
  188. else if(nsemi1==3)
  189. {cout<<(((x[0][0])*((x[2][2]*x[1][1])-(x[2][1]*x[1][2])))
  190. -((x[1][0])*((x[0][1]*x[2][2])-(x[0][2]*x[2][1])))+
  191. ((x[2][0])*((x[0][1]*x[1][2])-(x[0][2]*x[1][1]))));
  192.  
  193. }
  194. else 
  195. {
  196.  
  197.  cout<< x[0][0]*((x[1][1]*(x[3][3]*x[2][2]-x[2][3]*x[3][2]))
  198. -(x[2][1]*(x[3][3]*x[1][2]-x[1][3]*x[3][2]))+
  199. (x[3][1]*(x[2][3]*x[1][2]-x[1][3]*x[2][2])))
  200.  
  201. -(x[1][0]*((x[0][1]*(x[2][2]*x[3][3]-x[2][3]*x[3][2]))
  202. -(x[2][1]*(x[0][2]*x[3][3]-x[0][3]*x[3][2]))+
  203. (x[3][1]*(x[0][2]*x[2][3]-x[0][3]*x[2][2]))))
  204.  
  205. +(x[2][0]*((x[0][1]*(x[1][2]*x[3][3]-x[1][3]*x[3][2]))
  206. -(x[1][1]*(x[0][2]*x[3][3]-x[0][3]*x[3][2]))+
  207. (x[3][1]*(x[0][2]*x[1][3]-x[0][3]*x[1][2]))))
  208.  
  209. -(x[3][0]*((x[0][1]*(x[1][2]*x[2][3]-x[1][3]*x[2][2]))
  210. -(x[1][1]*(x[0][2]*x[2][3]-x[0][3]*x[2][2]))+
  211. (x[2][1]*(x[0][2]*x[1][3]-x[0][3]*x[1][2]))));    
  212. }
  213.  
  214. }
  215. else{cout<<"ERROR";}
  216.  
  217. }
  218. /*power*/
  219. if(op=="^")
  220. {if(nsemi1==nspace1)
  221. {
  222.  
  223.     cin>>pow;
  224.     cout<<"[";
  225.     float mat[100][100];
  226.  
  227.     for(int k=0;k<pow-1;k++)
  228. {
  229. for(int i=0;i<nsemi1;i++)
  230. {
  231. for(int j=0;j<nspace1;j++)
  232. {
  233.  
  234. for(int m=0;m<nsemi1;m++)
  235. {mat[i][j]=x[i][j];
  236. z[i][j]=mat[i][j]+mat[i][j]*x[i][j];
  237. }
  238. }
  239. }
  240. for(int l=0;l<nsemi1;l++)
  241. {
  242.   for(int ab=0;ab<nsemi1;ab++)
  243. {
  244.   mat[l][ab]=z[l][ab];
  245. }
  246.  
  247. }
  248. }
  249. for(int i=0;i<nsemi1;i++)
  250. {
  251. for(int j=0;j<nspace1;j++)
  252. {
  253.  cout<<z[i][j]<<" ";
  254. }
  255.  cout<<";"    ;
  256. }
  257. cout<<"]";
  258.  
  259. }
  260.  
  261.  
  262.  else{
  263.      cout<<"ERROR";
  264.  }   
  265. }
  266.  
  267. return 0;
  268. }
Apr 29 '15 #12
zmbd
5,501 Expert Mod 4TB
esslam200
WFC is a very gracious and generous person and is normally a very helpful expert/moderator - please follow the advice the WFC has already given you:

Please run your compiler and troubleshoot the code. WFC and I have both stated that we cannot do your homework - this is a site policy:
Posting Homework or Coursework Questions and Answers
Any and all Homework/Coursework questions will be deleted. If you see a question that is a homework or coursework assignment then please remember DO NOT attempt to post a reply. Replies to this thread will be deleted along with the original post. Please 'report' the thread.
Apr 30 '15 #13
thank u all very much and i must mention WFC who let me think how to solve prgramming problems
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <sstream>
  3. #include<string>
  4. #include<math.h>
  5. #include <string>
  6. #include <cstdlib>
  7. using namespace std;
  8. float matrix[100][100],size,d;
  9.     int i,j;
  10.     float determinant(float matrix[100][100],float size)
  11. {
  12.     float s=1,det=0,m1[100][100];
  13.     int i,j,m,n,c;
  14.     if (size==1)
  15.     {
  16.         return (matrix[0][0]);
  17.     }
  18.     else
  19.     {
  20.         det=0;
  21.         for (c=0;c<size;c++)
  22.         {
  23.             m=0;
  24.             n=0;
  25.             for (i=0;i<size;i++)
  26.             {
  27.                 for (j=0;j<size;j++)
  28.                 {
  29.                     m1[i][j]=0;
  30.                     if (i != 0 && j != c)
  31.                     {
  32.                        m1[m][n]=matrix[i][j];
  33.                        if (n<(size-2))
  34.                           n++;
  35.                        else
  36.                        {
  37.                            n=0;
  38.                            m++;
  39.                        }
  40.                     }
  41.                 }
  42.             }
  43.             det=det + s * (matrix[0][c] * determinant(m1,size-1));
  44.             s=-1 * s;
  45.         }
  46.     }
  47.  
  48.     return (det);
  49. }
  50. int main ()
  51. {
  52.     string a1,c1,c2,e1,r1,t,b1,v1,v2,e2,r2,l,ope;
  53.     float x1[100][100],y1[100][100],z1[100][100],k1[100][100],u=0;
  54.     int i,j,n1,m1,n2,m2,na,nb,sum1=1,sum2=1,a2,a3,a4,a5,b2,b3,b4,b5,q,sum3=1,sum4=1,power;
  55.  
  56. getline(cin,a1);
  57. a2=a1.length();
  58. for (i=0;i<a2;i++)
  59. {if (a1[i]==';')
  60. sum1 = sum1 +1 ;
  61.  
  62. }
  63. n1=sum1 ;
  64. for (int i=0;i<a2;i++)
  65. {if (a1[i]==' ')
  66. sum2=sum2+1;
  67. if(a1[i]==';')
  68. break;
  69. }
  70. m1=sum2;
  71. c2=a1.substr(1,a2-2);
  72. c2=c2+";";
  73. t= " ";
  74. for ( i =0; i<n1;i++)
  75.     { 
  76.  
  77.           e1 = c2.substr(0,(c2.find(';')));
  78.          t= t +" "+e1;
  79.          c2=c2.erase(0,c2.find(';')+1);
  80.     }
  81.  a3= t.length();
  82.     t=t.substr(1);
  83.         t=t.substr(1);
  84. for( i=0;i<n1;i++)
  85. {for ( j=0;j<m1;j++)
  86. {a4=t.find(' ');
  87. a5=t.find(' ');
  88. r1=t.substr(0,a4);
  89. x1[i][j]=atof(r1.c_str());
  90. t=t.erase(0,a5+1);
  91. }
  92.     }
  93.     getline(cin,ope);
  94.     if(ope=="-"||ope=="+"||ope=="/"||ope=="*")
  95.     {
  96.         getline(cin,b1);
  97.         b2=b1.length();
  98. for (i=0;i<b2;i++)
  99. {if (b1[i]==';')
  100. sum3 = sum3 +1 ;
  101.  
  102. }
  103. n2=sum3 ;
  104. for ( i=0;i<b2;i++)
  105. {if (b1[i]==' ')
  106. sum4=sum4+1;
  107. if(b1[i]==';')
  108. break;
  109. }
  110. m2=sum4;
  111. v2=b1.substr(1,b2-2);
  112. v2=v2+";";
  113. l= " ";
  114. for ( i =0; i<n2;i++)
  115.     { 
  116.  
  117.           e2 = v2.substr(0,(v2.find(';')));
  118.          l= l +" "+e2;
  119.          v2=v2.erase(0,v2.find(';')+1);
  120.     }
  121.  b3= l.length();
  122.     l=l.substr(1);
  123.         l=l.substr(1);
  124. for( i=0;i<n2;i++)
  125. {for ( j=0;j<m2;j++)
  126. {b4=l.find(' ');
  127. b5=l.find(' ');
  128. r2=l.substr(0,b4);
  129. y1[i][j]=atof(r2.c_str());
  130. l=l.erase(0,b5+1);
  131. }
  132. }
  133. if(ope=="+"){
  134.     if(n1==n2&&m1==m2)
  135. {
  136.     cout<<"[";
  137.  
  138. for(i=0;i<n1;i++)
  139.     {for( j=0;j<m1;j++)
  140.     {z1[i][j]=x1[i][j]+y1[i][j];
  141.     if(j!=(m1-1))
  142.     cout<<z1[i][j]<<" ";
  143.     else 
  144.     cout<<z1[i][j];
  145.  
  146.     }
  147.     if(i!=(n1-1))
  148.     cout<<";";
  149.     else
  150.     continue;
  151.  
  152.     }
  153.     cout<<"]";
  154.  
  155.     }
  156. else {cout<<"ERROR";}
  157.  
  158.     }
  159.  
  160.     if(ope=="-")
  161.     {if(n1==n2&&m1==m2)
  162. {
  163.     cout<<"[";
  164.  
  165. for(i=0;i<n1;i++)
  166.     {for( j=0;j<m1;j++)
  167.     {z1[i][j]=x1[i][j]-y1[i][j];
  168.     if(j!=(m1-1))
  169.     cout<<z1[i][j]<<" ";
  170.     else 
  171.     cout<<z1[i][j];
  172.  
  173.     }
  174.     if(i!=(n1-1))
  175.     cout<<";";
  176.     else
  177.     continue;
  178.  
  179.     }
  180.     cout<<"]";
  181.  
  182.     }
  183. else {cout<<"ERROR";}
  184.  
  185.     }
  186.  
  187. if(ope=="*")
  188. {if(m1==n2)
  189.  
  190.  
  191.  
  192. {
  193. cout<<"[";
  194. for(int i=0;i<n1;i++)
  195. {
  196. for(int j=0;j<m2;j++)
  197. {
  198. z1[i][j]=0;
  199. for(int q=0;q<n2;q++)
  200. {
  201. z1[i][j]=z1[i][j]+x1[i][q]*y1[q][j];
  202. }
  203. }
  204. }
  205.  
  206. for(int i=0;i<n1;i++)
  207. {
  208. for(int j=0;j<m2;j++)
  209. {
  210. if(j!=(m2-1))
  211.     cout<<z1[i][j]<<" ";
  212.     else 
  213.     cout<<z1[i][j];
  214.  
  215.     }
  216.     if(i!=(n1-1))
  217.     cout<<";";
  218.     else
  219.     continue;
  220.  
  221.     }
  222.     cout<<"]";
  223.  
  224.     }
  225. else {cout<<"ERROR";}
  226.  
  227.     }
  228.         if(ope=="/"){
  229.             if(m1==n2){
  230.  
  231.     float raa[100][100],rbb[100][100];
  232.      int p,q,m,n,i,j;
  233.      for (q=0;q<n1;q++)
  234.      {
  235.          for (p=0;p<n2;p++)
  236.          {
  237.              m=0;
  238.              n=0;
  239.              for (i=0;i<n2;i++)
  240.              {
  241.                  for (j=0;j<n2;j++)
  242.                  {
  243.                      if (i != q && j != p)
  244.                      {
  245.                         raa[m][n]=y1[i][j];
  246.                         if (n<(n2-2))
  247.                            n++;
  248.                         else
  249.                         {
  250.                             n=0;
  251.                             m++;
  252.                         }
  253.                      }
  254.                  }
  255.              }
  256.              rbb[q][p]=pow(-1,q + p) * determinant(raa,n2-1);
  257.          }
  258.      }
  259. float kaa[100][100],d1;
  260.  
  261.      for (i=0;i<n2;i++)
  262.      {
  263.          for (j=0;j<n2;j++)
  264.          {
  265.              kaa[i][j]=rbb[j][i];
  266.          }
  267.      }
  268.      d=determinant(y1,n2);
  269.      for (i=0;i<n2;i++)
  270.      {
  271.          for (j=0;j<n2;j++)
  272.          {
  273.             y1[i][j]=kaa[i][j] / d;
  274.          }
  275.      }
  276.     for(int i=0;i<n1;i++)
  277. {
  278. for(int j=0;j<m2;j++)
  279. {
  280. z1[i][j]=0;
  281. for(int q=0;q<n2;q++)
  282. {
  283. z1[i][j]=z1[i][j]+x1[i][q]*y1[q][j];
  284. }
  285. }
  286. }
  287.  
  288.  
  289.     cout<<"[";
  290.     for(int i=0;i<n1;i++)
  291. {
  292. for(int j=0;j<m2;j++)
  293. {
  294. if(j!=(m2-1))
  295.     cout<<z1[i][j]<<" ";
  296.     else 
  297.     cout<<z1[i][j];
  298.  
  299.     }
  300.     if(i!=(n1-1))
  301.     cout<<";";
  302.     else
  303.     continue;
  304.  
  305.     }
  306.     cout<<"]";
  307.  
  308.     }
  309.     else cout<<"ERORR";
  310. }
  311.  
  312.  
  313. }
  314.  
  315.  
  316.  
  317.  
  318. else if(ope=="^"||ope=="T"||ope=="D"||ope=="I")
  319. {
  320.  
  321.     if(ope=="T"){
  322.         for (int i=0;i<a2;i++)
  323. {if (a1[i]==' ')
  324. {u++;}
  325.  
  326. }
  327. u=(u/n1)+1;
  328. int s = u;
  329. if(u!= s){
  330. cout<<"ERORR";}
  331. else {
  332.  
  333.     cout<<"[";
  334.     for( int i=0;i<m1;i++)
  335. {for( j=0;j<n1;j++)
  336. {
  337.  
  338. cout<<x1[j][i]<<" ";
  339. }
  340. cout<<";"    ;
  341. }
  342. cout<<"]";}}
  343.  
  344. if(ope=="D"){
  345.     if(n1!=m1)
  346.     cout<<"ERORR";
  347.  
  348. cout<<determinant(x1,n1);
  349. }
  350. if(ope=="^"){
  351.     if(n1==m1)
  352. {
  353.  
  354.     cin>>power;
  355.     cout<<"[";
  356.  
  357. for(i=0;i<n1;i++)
  358. {
  359.   for(j=0;j<m1;j++)
  360.     {
  361.      z1[i][j]=x1[i][j];
  362.     }
  363. }
  364.  
  365. float t =0;
  366. for(int m=0;m<power-1;m++)
  367.  {
  368.     for( i=0;i<n1;i++)
  369.     {
  370.         for( j=0;j<m1;j++)
  371.         {
  372.             for(q=0;q<m1;q++)
  373.                 {
  374.                     t=t+z1[i][q]*x1[q][j];
  375.                 }
  376.                 k1[i][j]=t;
  377.                 t=0;
  378.         }
  379.     }
  380.     for( i=0;i<n1;i++)
  381.     {
  382.           for( j=0;j<m1;j++)
  383.         {
  384.          z1[i][j]=k1[i][j];
  385.         }
  386.     }
  387.  }
  388.  
  389.  
  390.  
  391. for( i=0;i<n1;i++)
  392. {
  393. for( j=0;j<m1;j++)
  394. {
  395. if(j!=(m1-1))
  396.     cout<<z1[i][j]<<" ";
  397.     else 
  398.     cout<<z1[i][j];
  399.  
  400.     }
  401.     if(i!=(n1-1))
  402.     cout<<";";
  403.     else
  404.     continue;
  405.  
  406.     }
  407. cout<<"]";
  408.  
  409.     }
  410.  
  411.  else{cout<<"ERROR";
  412.  
  413.  }   
  414. }
  415. }
  416. if(ope=="I"){
  417.     if(n1==m1)
  418. {
  419.     cout<<"[";
  420.  float r11[100][100],r22[100][100];
  421.      int p,q,m,n,i,j;
  422.      for (q=0;q<n1;q++)
  423.      {
  424.          for (p=0;p<n1;p++)
  425.          {
  426.              m=0;
  427.              n=0;
  428.              for (i=0;i<n1;i++)
  429.              {
  430.                  for (j=0;j<n1;j++)
  431.                  {
  432.                      if (i != q && j != p)
  433.                      {
  434.                         r11[m][n]=x1[i][j];
  435.                         if (n<(n1-2))
  436.                            n++;
  437.                         else
  438.                         {
  439.                             n=0;
  440.                             m++;
  441.                         }
  442.                      }
  443.                  }
  444.              }
  445.              r22[q][p]=pow(-1,q + p) * determinant(r11,n1-1);
  446.          }
  447.      }
  448. float k11[100][100],d;
  449.  
  450.      for (i=0;i<n1;i++)
  451.      {
  452.          for (j=0;j<n1;j++)
  453.          {
  454.              k11[i][j]=r22[j][i];
  455.          }
  456.      }
  457.      d=determinant(x1,n1);
  458.      for (i=0;i<n1;i++)
  459.      {
  460.          for (j=0;j<n1;j++)
  461.          {
  462.             z1[i][j]=k11[i][j] / d;
  463.          }
  464.      }
  465.  
  466.      for (i=0;i<n1;i++)
  467.      {
  468.          for (j=0;j<n1;j++)
  469.          {
  470.             cout<<z1[i][j]<<" ";
  471.          }
  472.          cout<<";";
  473. }
  474. cout <<"]";
  475. }
  476. else cout<< "ERROR";
  477.     }
  478. return 0;
  479. }
  480.  
  481.  
  482.  
May 11 '15 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Matt | last post by:
Any progammers looking for a killer app to develop? How about a voice enabled forum? One of the most powerful, exciting, and engrossing experiences on the Internet is the Forum. The first great...
6
by: memocan | last post by:
#include <iostream> using namespace std; int x; //global variable matrix int main() { x= new float ; //initialize the size now }
8
by: nestini | last post by:
Hello everybody, I am student who just begin learning about programming I want to know what is Sprase Matrix. And would you please show me how to add the 2 Sprase Matrix in C soursecode.
4
by: L. | last post by:
Hello, I need to generate random Matrices (say of size 5*5), each with an average of X (say X=0.5), but with different values’ range. One matrix should have values in the range of 0-1, while...
7
by: Brad | last post by:
When debugging my current web project, in VS2003, I found I had lost the ability to drill down on watch objects in the Watch Window; I could only view the single value specific watch objects. ...
3
by: Gary Kahrau | last post by:
If I create a solution that contains (2) projects. ProjMain and Proj2. Each project has a form1. I want to press a button in ProjMain and show form1 of Proj2. How do I do this? Gary...
3
by: barry | last post by:
Hi Which IDE is used to develop project using .ASP and global.asa files, Visual Studio 2003 allows creating of C# projects which use .apsx , c# files, i have not been able to see any option to...
0
by: Daniel Crespo | last post by:
Hi to all, Does anyone know about how to make a dot matrix printer print a PDF file with the quality of a Microsoft Word printing? When I print from Microsoft Word, the output is perfect for...
1
by: Thomas Bauer | last post by:
Hello, how can I make the transformation matrix? Zero point Left top Left bottom Right top Right bottom
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.