矩阵的方向导数 [英] Directional Derivatives of a Matrix

查看:272
本文介绍了矩阵的方向导数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作区中有40个结构.我需要编写一个脚本来计算所有元素的方向导数.这是代码:

I have 40 structures in my Workspace. I Need to write a script to calculate the directional derivatives of all the elements. Here is the code :

[dx,dy] = gradient(Structure_element_1.value);  
dxlb = min(min(dx));  
dxub = max(max(dx));  
dylb = min(min(dy));  
dyub = max(max(dy));  

[ddx,ddy] = gradient(gradient(Structure_element_1.value));
ddxlb = min(min(ddx));  
ddxub = max(max(ddx));
ddylb = min(min(ddy));
ddyub = max(max(ddy));  

这是一个元素的代码.我需要找出所有40个元素相同的元素,然后再使用.任何人都可以帮忙.

This is the code for one element. I Need to find out the same for all the 40 elements and then use it later. Can anyone help with this.

推荐答案

要回答您的字面问题,您应该将变量存储在

To answer your literal question, you should store the variables in a structure array or at least a cell array. If all of your structures have the same fields, you can access all of them by indexing a single array variable, say Structure_element:

for i = 1:numel(Structure_element)
    field = Structure_element(i).value
    % compute gradients of field
end

现在要解决实际梯度计算的问题. gradient 函数计算,其中是您的数据矩阵.通常,MATLAB函数会知道请求了多少个输出参数.调用gradient(gradient(F))时,内部gradient调用的 first 输出上将调用外部gradient.这意味着您当前正在获得.

Now to address the issue of the actual gradient computation. The gradient function computes an approximation for , where is your matrix of data. Normally, a MATLAB function is aware of how many output arguments are requested. When you call gradient(gradient(F)), the outer gradient is called on the first output of the inner gradient call. This means that you are currently getting an approximation for .

我怀疑您确实是在尝试获取.为此,您必须从内部调用gradient中获取两个输出,并将它们分别传递给 外部调用,然后选择正确的输出:

I suspect that you are really trying to get . To do this, you have to get both outputs from the inner call to gradient, pass them separately to the outer call, and choose the correct output:

[dx,dy] = gradient(F);
[ddx, ~] = gradient(dx);
[~, ddy] = gradient(dy);

请注意分开的通话.引入了波浪号作为<忽略函数自变量 /blogs.mathworks.com/loren/2009/09/11/matlab-release-2009b-best-new-feature-or/"rel =" nofollow> MATLAB 2009b版.如果您使用的是旧版本,只需使用名为junk或类似名称的实际变量即可.

Note the separated calls. The tilde was introduced as a way to ignore function arguments in MATLAB Release 2009b. If you have an older version, just use an actual variable named junk or something like that.

这篇关于矩阵的方向导数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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