加载中
加载中
表情图片
评为精选
鼓励
加载中...
分享
加载中...
文件下载
加载中...
修改排序
加载中...
[求助] 用VB数组解决矩阵乘法
carneades2009/10/30软件综合 IP:江苏
我尝试用VB的数组编写一个3*3矩阵计算器,可是在遇到表达式的时候,要么卡壳,要么得到一些莫名其妙的结果。麻烦会得分帮忙看一下那里出问题了,应该怎么改。谢谢!

本程序的功能除了实现矩阵乘法,还要求出每个矩阵的行列式。(通过矩阵下方的“”det()=按实现)

我已经用C语言实现了这种算法,代码如下:
#include <stdio.h>
#include <math.h>
void main()
{
  #define M 3 /*left row*/
  #define S 3 /*left column & right row*/
  #define N 3 /*right column*/

  int a[M][S],b[S][N],c[M][N]={0,0,0}/*Adjust the number of "0" when n is changed!*/;
  int i,j,s;
  char ch='Y';

  do{

  printf("Input the elements of the left matrix by row.\n");
  for(i=0;i<M;i++)
  {
    for(j=0;j<S;j++)
    {
      scanf("%d",&a[i][j]);
    }
    printf("\n");
  }

  printf("Input the elements of the right matrix by row.\n");
  for(i=0;i<S;i++)
  {
    for(j=0;j<N;j++)
    {
      scanf("%d",&b[i][j]);
    }
    printf("\n");
  }

  printf("The product is:\n");
  for(i=0;i<M;i++)
  {
    for(j=0;j<N;j++)
    {
      for(s=0;s<S;s++)
      {
         c[i][j]+=a[i][s]*b[s][j];
      }
      printf("%d\t",c[i][j]);
    }
    printf("\n");
  }

  printf("Continue?(Y/N)\n");
  ch=getchar();
  
  }while(ch=='Y'||ch=='y');
} product.jpg

attachment icon matrix1.rar 2.10KB RAR 30次下载
product2.jpg
来自:计算机科学 / 软件综合
11
新版本公告
~~空空如也
carneades 作者
15年8个月前 IP:未同步
161573
谢谢楼上诸位的关注!

学了C语言后就觉得VB的语句忒啰嗦。
我最近学习线性代数,同学们苦于矩阵运算的麻烦,希望我给他们做一个程序。
我现在用最土得办法——把行列式展开成代数式求解,这居然还卡壳!

Private Sub cmda_Click()
    Dim a11 As Integer, a12 As Integer, a13 As Integer
    Dim a21 As Integer, a22 As Integer, a23 As Integer
    Dim a31 As Integer, a32 As Integer, a33 As Integer
    Dim dta As Integer
    
    a11 = Val(a11.Text): a12 = Val(a12.Text): a13 = Val(a13.Text)
    a21 = Val(a21.Text): a22 = Val(a22.Text): a23 = Val(a23.Text)
    a31 = Val(a31.Text): a32 = Val(a32.Text): a33 = Val(a33.Text)
    
    dta = (a11 * a22 * a33) + (a12 * a23 * a31) + (a21 * a32 * a13) - (a31 * a22 * a13) - (a21 * a12 * a33) - (a32 * a23 * a11)
    
    dta.Text = Str(dta)
End Sub

在运行这段语句的时候,卡在a11 = Val(a11.Text): 这里了。说什么“编译错误,无效限定符”。
控件的名字弄得跟变量一样要紧吗?
引用
评论
加载评论中,请稍候...
200字以内,仅用于支线交流,主线讨论请采用回复功能。
折叠评论

想参与大家的讨论?现在就 登录 或者 注册

所属专业
上级专业
同级专业
carneades
笔友
文章
18
回复
479
学术分
0
2008/08/18注册,7年10个月前活动
暂无简介
主体类型:个人
所属领域:无
认证方式:邮箱
IP归属地:未同步
插入公式
评论控制
加载中...
文号:{{pid}}
投诉或举报
加载中...
{{tip}}
请选择违规类型:
{{reason.type}}

空空如也

笔记
{{note.content}}
{{n.user.username}}
{{fromNow(n.toc)}} {{n.status === noteStatus.disabled ? "已屏蔽" : ""}} {{n.status === noteStatus.unknown ? "正在审核" : ""}} {{n.status === noteStatus.deleted ? '已删除' : ''}}
  • 编辑
  • 删除
  • {{n.status === 'disabled' ? "解除屏蔽" : "屏蔽" }}
我也是有底线的