Create an array of values of different values of an equation that depends of a list of parameters
3 views (last 30 days)
Show older comments
Hi,
Im currently tryng to solve a problem where I need to calculate q for diferent values of dx . Basically I just want to evaluate de expresion of q for every x. The code for that that I'm using is the following:
function out = heat(dx)
syms x
f = a*x^2 + b*x +c;
out = subs(f, x, dx);
out = double(out);
end
My intention is to create a for loop to fill the values of q in order to use it later in the main code, something like (:
for dx=1:10
q(i) = heat(dx) % q(i) is the the exresion f evaluated at dx
end
The problem that I have is that the parameters a, b and c are in reality defined in the main script so the function depends on those parameters.
I tryed to create a nested function but I still havent managed to find a solution. And honestly I have no idea how to do it.
How do I evaluate this dependend- parameter function and fill the array of values of my vairable q ?
0 Comments
Answers (1)
Milan Bansal
on 15 Sep 2023
Hi,
As per my understanding, you have created a function which is dependent on some parameters that are defined in a main script.
In order to use those parameters in the function, pass them in the function as arguments. Modify your function as shown in the code below.
function out = heat(dx,a,b,c)
syms x
f = a*x^2 + b*x +c;
out = subs(f, x, dx);
out = double(out);
end
To use this function in the "for" loop, modify the code in the main script.
for dx=1:10
q(i) = heat(dx,a,b,c) % q(i) is the the expression f evaluated at dx
end
Refer to the documentation link to know more about MATLAB Functions.
0 Comments
See Also
Categories
Find more on Number Theory in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!