Clear Filters
Clear Filters

Source function f in pde toobox

2 views (last 30 days)
Lewis Bartel
Lewis Bartel on 26 Mar 2021
Answered: Anurag Ojha on 7 May 2024
It appears that a function to represent a source f = fcoefficient(location,state) does not allow for complex inputs. I want to couple equations where the source for one of the components is a complex quantity; e.g., f(4,:) is a function of solutions of the other components. These solutions are complex.

Answers (1)

Anurag Ojha
Anurag Ojha on 7 May 2024
Hello Lewis
In MATLAB, you can work with complex numbers and perform operations on them. If you want to represent a complex source function, you can define it as a function handle that takes complex inputs.
Adding a sample code for your reference
% Define the source function
f = @(location, state) complexFunction(location, state);
% Define the complex function
function result = complexFunction(location, state)
% Perform operations on complex inputs
result = state(1,:) + 1i*state(2,:);
end
In the code above, the "complexFunction" takes two inputs "location" and "state", where "state" is a matrix of complex solutions for other components. The function performs operations on the complex inputs and returns a complex result.

Community Treasure Hunt

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

Start Hunting!