How do I access an element of an array of equations

1 回表示 (過去 30 日間)
Kerney Reynolds
Kerney Reynolds 2022 年 11 月 22 日
回答済み: John D'Errico 2022 年 11 月 22 日
This is the code I want to work
a = @(x) 3*x;
b = @(x) 5*x;
y =@(x) a(x):x:b(x);
y = y(x);
y(1)
a and b are functions of x so I want y to be 3x, 4x, 5x and I want to be able to acces an element (ex: 4x) but I can't figure out the syntax

回答 (1 件)

John D'Errico
John D'Errico 2022 年 11 月 22 日
If x is symbolic, you CANNOT use it in a colon call. But in the end, you did not ask for a symbolic result, but a function of x.
So trivially, you can do this:
a = @(x) 3*x;
b = @(x) 5*x;
y = @(x) (a(1):b(1))*x;
y(1)
ans = 1×3
3 4 5
y(3)
ans = 1×3
9 12 15

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by