如何在Matlab中集成矩阵函数? [英] How do I integrate a matrix function in Matlab?

查看:519
本文介绍了如何在Matlab中集成矩阵函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个函数,它带有一个实数 x ,并返回一个矩阵 M(x) 。我如何评估以下内容?





一个例子,我试图整合的函数是这样给出的: -





这里, k 是一个常量, A 是一个矩阵。

I尝试使用 int 函数,但它似乎只适用于标量函数。我是Matlab新手。有人可以帮我解决吗?

解决方案

Matlab(latest,2015)提供了积分函数用于数值计算函数积分

函数(如矩阵值函数),您可以使用'ArrayValued',true 选项



< blockquote>

向量值函数



创建向量值函数

$ f(x)= [sin x,sin 2x,sin 3x,sin 4x,sin 5x]


并从 x = 0到x = 1 进行整合。指定'ArrayValued',true
评估数组值或向量值函数的积分。

  fun = @(x)sin((1:5)* x); 
q = integral(fun,0,1,'ArrayValued',true)

q =

  0.4597 0.7081 0.6633 0.4134 0.1433 


或者,您可以整合矩阵值函数element-wise,即每个元素使用循环,另外,还可以尝试将操作向量化为一个不带循环的操作(例如,参见 here)



相关的关于scicomp.se的问题


Let's say I have a function which takes a real number x and returns a matrix M(x). How do I evaluate the following?

As an example, the function I'm trying to integrate is given by:-

Here, k is a constant and A is a matrix.

I tried using the int function, but it seems to work only for scalar functions. I'm new to Matlab. Could someone help me out?

解决方案

Matlab (latest, 2015) provides the integral function to numericaly compute integrals of functions

For functions that have a multi-dimensional domain (e.g matrix-valued functions) you can use the 'ArrayValued',true option

Vector-Valued Function

Create the vector-valued function

f(x) = [sin x, sin 2x, sin 3x, sin 4x, sin 5x]

and integrate from x=0 to x=1. Specify 'ArrayValued',true to evaluate the integral of an array-valued or vector-valued function.

fun = @(x)sin((1:5)*x);
q = integral(fun,0,1,'ArrayValued',true)

q =

0.4597    0.7081    0.6633    0.4134    0.1433

Alternatively, you can integrate the matrix-valued function element-wise, i.e per-element using loops, plus, one can also try to vectorize the operation to one without-loops (for example see here)

related question on scicomp.se

这篇关于如何在Matlab中集成矩阵函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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