How do I access an element of an array of equations

1 visualizzazione (ultimi 30 giorni)
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

Risposte (1)

John D'Errico
John D'Errico il 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

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by