How do I access an element of an array of equations

1 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by