How do I access an element of an array of equations

1 view (last 30 days)
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

Answers (1)

John D'Errico
John D'Errico on 22 Nov 2022
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

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!