'How to sum functions in MATLAB under a condition
I'm trying to write a function that sums a bunch of functions and I have no idea what I'm doing wrong. My code:
function [f_max,x_max] = ftot(l,a,E,J,F)
% a and F are arrays
f_max = 0;
b = l-a;
n = length(F);
f1 = 0;
syms x
for j=1:n
y1 = piecewise(x<=a(j),1,x>a(j),0);
y2 = piecewise(x<=a(j),0,x>a(j),1);
f = (F(j)*b(j)*x)*y1 + (F(j)*b(j)*x^3)*y2;
f1 = f1 + f;
end
Basically I want to create a function that is the sum of F(j)*b(j)*x for j=1:n when x<=a and F(j)*b(j)*x^3 when x>a. How can I accomplish that?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
