声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1816|回复: 5

[编程技巧] 求广义逆时出错

[复制链接]
发表于 2007-7-3 21:35 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
A=[1,1;2,2]
A =
     1     1
     2     2
>> B=vpa(A)

B =

[ 1., 1.]
[ 2., 2.]

>> pinv(B)
??? Error using ==> svd
Too many input arguments.

Error in ==> D:\MATLAB6p5\toolbox\matlab\matfun\pinv.m
On line 20  ==>    [U,S,V] = svd(A,0);



请教各位大侠,这个问题怎么解决.我是个初学者,在编程时遇到了类似的问题.
我现在必须用vpa求出数组的精确解.但应用vpa后,就不能用pinv求该数组的广义逆了.就出现了上面的问题,不知应怎么解决.

[ 本帖最后由 eight 于 2007-7-5 15:03 编辑 ]
回复
分享到:

使用道具 举报

发表于 2007-7-4 10:31 | 显示全部楼层

回复 #1 lnly 的帖子

把整个程序贴上来看看
 楼主| 发表于 2007-7-4 15:05 | 显示全部楼层
clc
clear
syms theta
u0=(4*pi)*(10^-7);N=180;i0=2;R=25;thick=25;e=0.04;r=24.55;wide=10;alf=pi/4;L=219;
Kc=u0*N^2*i0^2*R*thick/8;
Ce=e/(R-r);
sumx=0.0;
for jj=1:4
    if(jj==1)
        n=0;
    elseif(jj==2)
        n=3;
    elseif(jj==3)
        n=4;
    else
        n=7;
        end
theta1=pi*(1+2*n)/8-asin(wide/(2*R));theta2=pi*(1+2*n)/2+asin(wide/(2*R));
A=Kc/(R-r)^2;
B=sin(theta)/[1-Ce*cos(alf-theta)]^2;
F=simple(int(B,theta,theta1,theta2))%,latex(F)
vpa(F,60);
Fx1y=A*F
vpa(Fx1y,60);
sumx=sumx+vpa(Fx1y,60);
end
sumx
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
sumy=0.0;
for jj=1:4
    if(jj==1)
        n=1;
    elseif(jj==2)
        n=2;
    elseif(jj==3)
        n=5;
    else
        n=6;
        end
theta1=pi*(1+2*n)/8-asin(wide/(2*R));theta2=pi*(1+2*n)/2+asin(wide/(2*R));
A=Kc/(R-r)^2;
B=cos(theta)/[1-Ce*cos(alf-theta)]^2;
F=simple(int(B,theta,theta1,theta2));%,latex(F)
vpa(F,60);
Fy1x=A*F ;
vpa(Fy1x,60);
sumy=sumy+vpa(Fy1x,60);
end
sumy
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
下面还有一半
 楼主| 发表于 2007-7-4 15:14 | 显示全部楼层
接着上面的程序
e1x=e*cos(alf)
e1y=e*sin(alf)
e2x=(2*L/thick)*e*cos(alf)
e2y=(2*L/thick)*e*sin(alf)

Ky1x=sumy/e1x
Ky2x=sumy/e2x
Kx1y=sumx/e1y
Kx2y=sumx/e2y
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
w=1000;m=1.5;l=219;a=109;b=110;D=49.1;k1=2.5;k2=0.01;k3=249.33;k4=203.24;k5=1.25e+3;k6=1.01e+3;
j1=pi*D^4/32;
j2=pi*D^4/64;
M=[m*b/l,m*a/l,0,0;0,0,m*b/l,m*a/l;-j2/l,j2/l,0,0;0,0,-j2/l,j2/l];
C=[k3*k2,k4*k2,0,0;0,0,k3*k2,k4*k2;-a*k3*k2,b*k4*k2,w*j1/l,-w*j1/l;-w*j1/l,w*j1/l,-a*k3*k2,b*k4*k2];
K=[(k5+k3*k1+Ky1x),(k6+k4*k1+Ky2x),0,0;0,0,(k5+k3*k1+Kx1y),(k6+k4*k1+Kx2y);-a*(k3*k1+k5+Ky1x),b*(k6+k4*k1+Ky2x),0,0;0,0,-a*(k3*k1+k5+Kx1y),b*(k6+k4*k1+Kx2y)];
I=eye(4);
mm=zeros(4);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%转换为标准特征值问题

G=[mm,I;-inv(M)*K,-inv(M)*C];
cri=eig(G)
pp=imag((cri));
wn=(abs(imag(cri)));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   A1=[-wn(1,1)^2*M(1,2)+...
      i*wn(1,1)*C(1,2)+K(1,2),...
   -wn(1,1)^2*M(1,3)+i*wn(1,1)...
       *C(1,3)+K(1,3),-wn(1,1)^2*...
   M(1,4)+i*wn(1,1)*C(1,4)+K(1,4);...
    -wn(1,1)^2*M(2,2)+i*wn(1,1)*C(2,2)+K(2,2), -wn(1,1)^2*M(2,3)+i*wn(1,1)*C(2,3)+K(2,3), -wn(1,1)^2*M(2,4)+i*wn(1,1)*C(2,4)+K(2,4);...
     -wn(1,1)^2*M(3,2)+i*wn(1,1)*C(3,2)+K(3,2),-wn(1,1)^2*M(3,3)+i*wn(1,1)*C(3,3)+K(3,3),-wn(1,1)^2*M(3,4)+i*wn(1,1)*C(3,4)+K(3,4);...
-wn(1,1)^2*M(4,2)+i*wn(1,1)*C(4,2)+K(4,2),-wn(1,1)^2*M(4,3)+i*wn(1,1)*C(4,3)+K(4,3),-wn(1,1)^2*M(4,4)+i*wn(1,1)*C(4,4)+K(4,4)]
B1=-[-wn(1,1)^2*M(1,1)+i*wn(1,1)*C(1,1)+K(1,1); -wn(1,1)^2*M(2,1)+i*wn(1,1)*C(2,1)+K(2,1);-wn(1,1)^2*M(3,1)+i*wn(1,1)*C(3,1)+K(3,1); -wn(1,1)^2*M(4,1)+i*wn(1,1)*C(4,1)+K(4,1)]

X(:,1)=pinv(A1)*(B1)
input('The program is over!')
运行后总有这样的错误:
??? Error using ==> svd
Too many input arguments.

Error in ==> D:\MATLAB6p5\toolbox\matlab\matfun\pinv.m
On line 20  ==>    [U,S,V] = svd(A,0);

Error in ==> D:\MATLAB6p5\work\MATLAB\练习\zhenxing4.m
On line 86  ==> X(:,1)=pinv(A1)*(B1)
发表于 2007-7-5 01:49 | 显示全部楼层
原帖由 lnly 于 2007-7-3 21:35 发表
A=[1,1;2,2]
A =
     1     1
     2     2
>> B=vpa(A)

B =

[ 1., 1.]
[ 2., 2.]

>> pinv(B)
??? Error using ==> svd
Too many input arguments.
Error in ==> D:\MATLAB6p5\toolbox\ma ...


A是个矩阵(double类型的),B的类型是sym,不能直接传递给pin()求解,所以报错说输入参数不对.
将原来程序中的
X( : ,1 )=pinv(A1)*(B1)这一句修改成
A_1=double(A1);B_1=double(B1);
X( : ,1 )=pinv(A_1)*(B_1)
就没事了.如果想看X( : ,1 )精确形式,可以再用vpa(X)看一下,跟楼主想要的应该是一样的.不知道说的对不对.

评分

1

查看全部评分

 楼主| 发表于 2007-7-5 08:40 | 显示全部楼层
谢谢了!我明白了!:@)
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-11-18 22:58 , Processed in 0.059244 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表