Change a variable in a function.
19 visualizzazioni (ultimi 30 giorni)
Im using the fsolve function inside a loop and there is an integer inside the fsolve function that will change the solution of the fsolve, i want to increment that number each time the loop is conducted, i defined the term in global and gave it a value of 1 intially, then i tried using A=A+1 inside the loop but the fsolve gave me the final answer only to that equation and i tried putting the A=A+1 inside the function but it gave me an error.
Nicolas B. il 28 Nov 2019
I never tried with global variables but, in your case, I would recommend you to set your A has an input. What I understand, all variables which are not inputs of the function_handle are set as constant in the function_handle when you define it (but I could be wrong). So I would recommand to define your function handle as:
A = 1;
f = @(in1, in2, A) you_function(in1, in2, A);
f(in1, in2, A);
A = A + 1;