adding k discrete functions together in a "for" loop
hello,
i'm trying to create a loop that creates individual discrete sine waves from a vector of sampled frequencies (locs), then adds those values together to create a single combined waveform. 
my code worked well symbolically:
syms tau

locs = [440 529 630] %example frequencies

combined = 0;

for k = 1:length(locs)
 figure
 hold on
 wave(k) = sin(2*pi*locs(k)*tau); %generate sin wave for each sampled frequency
 fplot(sin(2*pi*locs(k)*tau),[0 0.01])
 hold off
 combined = combined + wave(k); %add each generated sin wave to the previous one
end

figure
fplot(combined, [0 0.01])
but i am having trouble converting it to a discrete form. i get an error that says the indices on the left do not match the indices on the right, which i assume means that i am trying to put a 132300 element array (the sin function of t) into a 1x3 array (wave(k)). 
t = 0:1/44100:3;

locs = [440 529 630] %example frequencies

combined = 0;

for k = 1:length(locs)
 figure
 hold on
 wave(k) = sin(2*pi*locs(k)*t); %generate sin wave for each sampled frequency
 stem(sin(2*pi*locs(k)*t),[0 441]) 
 hold off
 combined = combined + wave(k); %add each generated sin wave to the previous one
end

figure
stem(combined, [0 441])
is there a better way to handle/store each of the generated sin waves so they can be added together in a discrete form?
if you do not need the "wave" contents for a further use, just drop out (k) from all its entries.
if you need it for a further use, initialize it as 
wave=zeros(3,numel(t));
before the loop and address it as wave(k,:) within the loop.
commands "stem" are definitely incorrect. if you want to see plots of the dependences on t, they should look something like stem(t,combined) or plot(t,combined), etc. however, the t range in the second version (0,3) is much wider than the one of the first version (0,0.01): consequently, such a graph will show much (hugely) more oscillations--you will probably see nothing but a unifromly painted square.
i do not see any need in the "nold on" and "hold off" commands in the both version.
the relationship of wavelength and frequency will appear as:using the wavelength range given, 280-320 nm, frequency range will be calculated using the equation above and by converting the values to the proper units [readmore]each wavelength must be in meters:we need to calculate the frequency for both 280 and 320 nm:range of frequency will appear as 1.07x1015 to 9.38x1014 s-1 The code is as shown below 

**clc;**

**close** **all;**

**clear** **all;**

**% define n**

**n = 0:18;**

**N = 19;** **% N tap filter**

**M = (N-1)/2;**

**% define window**

**% define the filter**

**h = 1./((n-M)*pi).*sin((n-M)*pi/5).*blackman(19)'.*((n>=0)-(n>=N));**

**h(M+1) = 2/15;** **% this corresponds to n=1 where the denominator is zero**

**% plot the filter**

**figure;**

**stem(n,h,'filled');grid** **on;title('h[n]');**

**xlabel('n');ylabel('stem height');**

**% plot the frequency response of the filter**

**figure;**

**freqz(h,1);grid** **on;**

  


  


![](/image?k=f31b88da6411d9811f191c8b336bed5e)![](/image?k=d351b5006ccd60c46820c64292935f2f) Hi,  
  
You can modify the inputs and outputs of any recipe in the Flow (by going to the Inputs/Outputs tab of this recipe), which allows you to replug parts of the flow elsewhere when needed. So you should be able to create your new joined dataset, and replug it to the rest of your Flow
 
 
 
 
 
 
 
 
 

[View solution in original post](/t5/Using-Dataiku-DSS/Insert-element-into-flow/m-p/2284#M1600) class intervals
frequency
(fi)
xi
di = xi - a
fi di


0 - 20
17
10
-40
-680


20 - 40
28
30
-20
-560


40 - 60
32
50 = a
0
0


60 - 80
p
70
20
20p


80 - 100
19
90
40
760


total
Î£
fi = 96 + p


Î£ fi di = 20p -
480


![](https://s3mn%20mnimgs%20com/img/shared/discuss_editlive/5130830/2013_07_08_13_01_36/mathmlequation8813644107607516415%20png) ok so, you're simply making a wrong aggregation in your y-axis. what you want to do is make 3 aggregations of type sum, each one for a specific category (men-women-children), like the following:

[[image]](https://aws1.discourse-cdn.com/elastic/original/3x/4/4/441907755076ca3a9417b959036a79f906d45448.png "image")

though, if you want to make something more professional and good-looking, since you're interes… let i = `(1)/(sinx*(3 + 2cosx))*dx` = `int sinx/(sin^2x*(3 + 2cosx))*dx` = `int sinx/((1 - cos^2x)(3 + 2cosx))*dx` = `int sinx/((1 - cosx)(1 + cosx)(3 + 2cosx))*dx` put cos x = t∴ – sinx.dx = dt∴ sinx.dx = – dt ∴ i = `int (1)/((1 - t)(1 + t)(3 + 2t))*(-dt)` = `int (-1)/((1 - t)(1 + t)(3 + 2t))*dt` let `(-1)/((1 - t)(1 + t)(3 + 2t)) = "a"/(1 - t) + "b"/(1 + t) + "c"/(3 + 2t)` ∴ – 1 = a(1 + t)(3 + 2t) + b(1 - t)(3 + 2t) + c(1 - t)(1 + t)put 1 – t = 0, i.e. t = 1, we get– 1 = a(2)(5) + b(0)(5) + c(0)(2) ∴ – 1 = 10a ∴ a = `(-1)/(10)`put 1 + t = 0, i.e. t = – 1, we get– 1 = a(0)(1) + b(2)(1) + c(2)(0) ∴ – 1 = 2b ∴ b = `-(1)/(2)` put 3 + 2t = 0, i.e. t = `-(3)/(2)`, we get – 1 = `"a"(-1/2)(0) + "b"(5/2)(0) + "c"(5/2)(-1/2)` ∴ – 1 = `-(5)/(4)"c"` ∴ c = `(4)/(5)` ∴ `(-1)/((1 - t)(1 + t)(3 + 2t)) = (((-1)/(10)))/(1 - t) + ((-1/2))/(1 + t) + ((4/5))/(3 + 2t)` ∴ i = `int [(((-1)/10))/(1 - t) + ((-1/2))/(1 + t) + ((4/5))/(3 + 2t)]*dt` = `-(1)/(10) int 1/(1 - t)*dt - (1)/(2) int 1/(1 + t)*dt + (4)/(5) int 1/(3 + 2t)*dt` = `-(1)/(10) (log|1 - t|)/(-1) - (1)/(2) log | 1 + t| + 4/5 (log|3 + 2t|)/(2) + c` = `(1)/(10)log|1 - cosx| - (1)/(2)log|1 + cosx| + (2)/(5)log|3 + 2cos| + c`. in case this is of further interest to anyone: i made some minor modifications to [@joels](/u/joels)' code to fetch the predicted values (plus cis) from effects only, which can then be fed into a ggplot. as long as ggeffects does not display confidence intervals, this allows to use the internally consistent pre… @pankajkumardas, 

converting geophysical data from the space (or time) domain to the frequency domain (via fast fourier transform) is common practice in geophysics, particularly when wanting to apply some sort of filter to that data. 

we do this because it is more computationally efficient to filter data in the frequency domain compared to the space domain. for example, applying a filter such as a first vertical derivative to a grid of magnetic data in the space domain requires convolution using a two-dimensional filter. depending on the type of filter, that process can be complex and therefore computationally expensive. 

transforming the data and the filter to the frequency domain allows us to simply multiply the two to get a filtered spectrum, which is then transformed back to a filtered grid in the space domain. this process is far more computationally efficient than convolution.

the following diagram describes the distinction between space and frequency domain filtering. it is taken from reeves (2005), which you can access here: http://www.geosoft.com/media/uploads/resources/technical-papers/aeromagnetic\_survey\_reeves.pdf




i'd urge you to download the document and review chapter 6, from which the diagram is taken.

best regards, hi andrew penny, - - just add this namespace definition: - xmlns:system=clr-namespace:system;assembly=mscorlib - - there are differences in parsing between wpf and silverlight and that is the reason we used the syntax below. if you develop silverlight application you can set it as follows: - - discreteobjectkeyframe keytime=0.00:00:00.0 value=2 /> - - - best wishes, - sia - the telerik team - - - do you want to have your say when we set our development plans? - do you want to know when a feature you care about is added or when a bug fixed? - explore the - telerik public issue tracking - system and vote to affect the priority of the items - - You are mixing [expressions](https://docs.microsoft.com/en-us/dotnet/api/system.linq.expressions.expression?view=netframework-4.7.1) with [lambda expressions](https://docs.microsoft.com/en-us/dotnet/api/system.linq.expressions.lambdaexpression?view=netframework-4.7.1). There are many posts showing how you can combine lambda expressions, but the essential part is to compose expressions from lambda expression [bodies](https://docs.microsoft.com/en-us/dotnet/api/system.linq.expressions.lambdaexpression.body?view=netframework-4.7.1) and rebind the [parameters](https://docs.microsoft.com/en-us/dotnet/api/system.linq.expressions.lambdaexpression.parameters?view=netframework-4.7.1).


The later is usually achieved by a custom [`ExpressionVisitor`](https://docs.microsoft.com/en-us/dotnet/api/system.linq.expressions.expressionvisitor?view=netframework-4.7.1) like this:



```
using System.Linq.Expressions;

public static class ExpressionExtensions
{
    public static Expression ReplaceParameter(this Expression expression, ParameterExpression source, Expression target)
    {
        return new ParameterReplacer { Source = source, Target = target }.Visit(expression);
    }

    class ParameterReplacer : ExpressionVisitor
    {
        public ParameterExpression Source;
        public Expression Target;
        protected override Expression VisitParameter(ParameterExpression node)
        {
            return node == Source ? Target : base.VisitParameter(node);
        }
    }
}

```

Now regarding the EF Core combined query filters. 


Using dictionaries and expression lists seems overcomplicated for what are you doing. Since [`IMutableEntityType`](https://docs.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.metadata.imutableentitytype?view=efcore-2.1) provides read/write access to the [`QueryFilter`](https://docs.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.metadata.imutableentitytype.queryfilter?view=efcore-2.1#Microsoft_EntityFrameworkCore_Metadata_IMutableEntityType_QueryFilter), the same can be achieved with a small set of a custom extension methods.


All they go inside a class like this:



```
using System;
using System.Linq.Expressions;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

public static class QueryFilterExtensions
{
}

```

First method:



```
public static void AddQueryFilter(this IMutableEntityType target, LambdaExpression filter)
{
    if (target.QueryFilter == null)
        target.QueryFilter = filter;
    else
    {
        var parameter = target.QueryFilter.Parameters[0];
        var left = target.QueryFilter.Body;
        var right = filter.Body.ReplaceParameter(filter.Parameters[0], parameter);
        var body = Expression.AndAlso(left, right);
        target.QueryFilter = Expression.Lambda(body, parameter);
    }
}

```

This is a non generic method which combines the exiting filter with passed filter using `AndAlso` (C# `&&`) operator and shows the aforementioned lambda expression combining principles.


However it's not so useful directly, like inside your entity type configuration loop (it can, but requires you to build manually the lambda expression instead of letting C# compiler do that). So here comes the second method:



```
public static void AddQueryFilter<T>(this IMutableEntityType target, Expression<Func<T, bool>> filter)
{
    LambdaExpression targetFilter = filter;
    if (target.ClrType != typeof(T))
    {
        var parameter = Expression.Parameter(target.ClrType, "e");
        var body = filter.Body.ReplaceParameter(filter.Parameters[0], parameter);
        targetFilter = Expression.Lambda(body, parameter);
    }
    target.AddQueryFilter(targetFilter);
}

```

It's a generic method - not quite type-safe, but allows you to use a compile time lambda expression and bind it to the actual entity type as follows:



```
foreach (var entityType in modelBuilder.Model.GetEntityTypes())
{
    if (typeof(IDeleted).IsAssignableFrom(entityType.ClrType))
        entityType.AddQueryFilter<IDeleted>(e => e.DateTimeDeleted == null);
}

```

Looks better, isn't it :)


The last custom extension method is complement to (replacement of) the standard EF Core generic [`HasQueryFilter`](https://docs.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.metadata.builders.entitytypebuilder-1.hasqueryfilter?view=efcore-2.1#Microsoft_EntityFrameworkCore_Metadata_Builders_EntityTypeBuilder_1_HasQueryFilter_System_Linq_Expressions_Expression_System_Func__0_System_Boolean___) method:



```
public static EntityTypeBuilder<TEntity> AddQueryFilter<TEntity>(this EntityTypeBuilder<TEntity> target, Expression<Func<TEntity, bool>> filter)
    where TEntity : class
{
    target.Metadata.AddQueryFilter(filter);
    return target;
}

```

and allows you to replace



```
this.AddToDict<DbMyEntity>(t => t.Name == null || t.Name == "Something");

```

with the more convenient



```
modelBuilder.Entity<DbMyEntity>()
    .AddQueryFilter(t => t.Name == null || t.Name == "Something");

```

**Update (EF Core 3.0):** `QueryFilter` property has been replaced with `GetQueryFilter` and `SetQueryFilter` extension methods.