Matrix function -- problem with the defi

조회 수: 2 (최근 30일)
Mikl Nik
Mikl Nik 2021년 1월 12일
답변: 埃博拉酱 2025년 1월 24일
Hi!
I wrote this code where Y is a cell array (actually is a matrix [y1; y2; y3] and F is a matrix that I would like to be like the function of Y -- I mean if Y = [y1; y2; y3] -> F(Y) = [1; y3; f(y1, y2, y3)] where f - another function.
How can I realize this in Matlab? Unfortunely this code does not work in an appropriate way. ;(
Thanks!
Y = @(y1, y2, y3) {@(y1) y1; @(y2) y2; @(y3) y3};
F = @(Y) [1; Y(3); f(Y(1), Y(2), Y(3))]
  댓글 수: 1
Aditya
Aditya 2025년 1월 24일
Hi Mikl,
To solve your problem with defining the function F(Y), you can use MATLAB's function handles and anonymous functions. These resources will guide you on how to define and work with them:
I hope this helps!

댓글을 달려면 로그인하십시오.

답변 (1개)

埃博拉酱
埃博拉酱 2025년 1월 24일
function Y=F(Y,f)
y3=Y(3,:);
Y(2:3,:)=[y3;f(Y(1,:),Y(2,:),y3)];
Y(1,:)=1;
end

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by