在Matlab中使用fzero时出错:类型为'function_handle'的输入参数未定义函数或方法'det' [英] Error using fzero in Matlab: Undefined function or method 'det' for input arguments of type 'function_handle'

查看:1786
本文介绍了在Matlab中使用fzero时出错:类型为'function_handle'的输入参数未定义函数或方法'det'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有本主题中描述的相同类型的问题: 使用fzero:未定义类型为'sym'的输入参数的函数或方法'isfinite'

I have the same kind of problem described in this topic: Using fzero: Undefined function or method 'isfinite' for input arguments of type 'sym'

他们的回答确实帮助了我,但我仍然受困.

Their answers really helped me, but I am still stuck.

我还必须找到w函数的零,该函数的定义步骤如下:

I also have to find the zeros of a function of w, this function is defined in several steps:

所以唯一的未知数是w,我定义了其他对象,例如:

So the only unknown is w, and I defined other objects such as:

lambda= @(w) ((16*rho(i)*A(i)*w^2*Lprime(i)^2)/(E(j)*I(i)))^0.25;

beta=@(w) lambda*b(i)^0.5;

gamma=@(w) lambda*Lprime(i)^0.5;

然后,我定义一个4 * 4矩阵M2:

Then, I define a 4*4 matrix M2:

M2=@(w) [besselj(4,beta) bessely(4,beta) besseli(4,beta) besselk(4,beta);
               besselj(3,beta) bessely(3,beta) besseli(3,beta) -besselk(3,beta);
               besselj(2,gamma) bessely(2,gamma) besseli(2,gamma) besselk(2,gamma);
               besselj(4,gamma) bessely(4,gamma) besseli(4,gamma) besselk(4,gamma)];

则要求解的方程是:det(M2)= 0.但是w = 0是解决方案之一,我想要第一个非零解决方案,所以我写道:

Then the equation to be solved is: det(M2)=0. But w=0 is one of the solutions, and I want the first non-zero solution, so I wrote:

delta = @(w) det(M2);

S(i,j)=fzero(delta,500);

然后我运行程序,Matlab说:

Then I run the program, and Matlab says:

??? Error using ==> fzero at 235
FZERO cannot continue because user supplied function_handle ==> @(w)det(M2)
failed with the error below.

Undefined function or method 'det' for input arguments of type 'function_handle'.

Error in ==> frequencies at 57
    S(i,j)=fzero(delta,500);

我也尝试了subs和eval方法,但它们也不起作用,在这些情况下,错误消息如下:

I also tried with the subs and the eval methods, and they don't work either, the error messages are in those cases:

??? Undefined function or method 'isfinite' for input arguments of type 'sym'.

Error in ==> fzero at 323
    elseif ~isfinite(fx) || ~isreal(fx)

Error in ==> frequencies at 58
    S(i,j)=fzero(@(w) subs(delta,'w',w),500);

我猜这与edio的错误相同.并且:

Which is the same error as edio's I guess. And:

??? Error using ==> fzero at 307
FZERO cannot continue because user supplied function_handle ==> @(w)eval(delta)
failed with the error below.

Undefined function or method 'eval' for input arguments of type 'function_handle'.

Error in ==> frequencies at 59
    S(i,j)=fzero(@(w)eval(delta),500);

你能帮我吗?

推荐答案

您的问题似乎是,当您将匿名函数放在其他匿名函数中时,您永远不会评估.例如,您将函数lambda定义如下:

Your problem appears to be that you are never evaluating your anonymous functions when you place them within other anonymous functions. For example, you define the function lambda as such:

lambda = @(w) ((16*rho(i)*A(i)*w^2*Lprime(i)^2)/(E(j)*I(i)))^0.25;

但是在beta中使用它时,您需要使用w的输入值对其进行评估,如下所示:

But when you use it in beta, you need to evaluate it using the input value for w, like so:

beta = @(w) lambda(w)*b(i)^0.5;
                %# ^--------------Pass w to lambda to evaluate the function

这样,我相信您的其他匿名函数应定义如下:

As such, I believe your other anonymous functions should be defined as follows:

gamma = @(w) lambda(w)*Lprime(i)^0.5;

M2 = @(w) [besselj(4,beta(w)) bessely(4,beta(w)) besseli(4,beta(w)) ...
           besselk(4,beta(w)); ...
           besselj(3,beta(w)) bessely(3,beta(w)) besseli(3,beta(w)) ...
           -besselk(3,beta(w)); ...
           besselj(2,gamma(w)) bessely(2,gamma(w)) besseli(2,gamma(w)) ...
           besselk(2,gamma(w)); ...
           besselj(4,gamma(w)) bessely(4,gamma(w)) besseli(4,gamma(w)) ...
           besselk(4,gamma(w))];

delta = @(w) det(M2(w));


我在这里注意到一个 GLARING 效率问题.通过使用匿名函数代替任何其他类型的函数(主要功能

There is a GLARING efficiency problem I'm noticing here. By using anonymous functions instead of any other type of function (primary functions, nested functions, or subfunctions) you are going to end up evaluating the same function with the same input multiple times over.

例如,每次评估M2来创建矩阵时,您将使用相同的输入对betagamma进行8次评估!注意将M2放在函数中并作为输入w传递,并且两个函数分别处理betagamma:

For example, each time you evaluate M2 to create your matrix you will be evaluating both beta and gamma 8 times with the same input! Notice the improvement you could make by placing M2 in a function and passing as input w and the two function handles beta and gamma:

function newMatrix = M2(w,betaFcn,gammaFcn)

  bw = betaFcn(w);   %# Evaluate the beta function once
  gw = gammaFcn(w);  %# Evaluate the gamma function once
  newMatrix = [besselj(4,bw) bessely(4,bw) besseli(4,bw) besselk(4,bw); ...
               besselj(3,bw) bessely(3,bw) besseli(3,bw) -besselk(3,bw); ...
               besselj(2,gw) bessely(2,gw) besseli(2,gw) besselk(2,gw); ...
               besselj(4,gw) bessely(4,gw) besseli(4,gw) besselk(4,gw)];

end

新的delta函数如下所示:

delta = @(w) det(M2(w,beta,gamma));

这篇关于在Matlab中使用fzero时出错:类型为'function_handle'的输入参数未定义函数或方法'det'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆